zoukankan      html  css  js  c++  java
  • 链队列java实现

    
    public class LinkHeap<T>
    {
        class Node<T>
        {
            T data;
            Node<T> next;
            Node(T data)
            {   
                this.data = data;
                this.next = null;
            }
        }
    
        Node<T> font ;
        Node<T> tail;
    
        public LinkHeap()
        {
            this.font = null;
            this.tail = null;
        }
    
        public boolean isEmpty()
        {
            return this.font==null && this.tail==null;
        }   
        public void enQueue(T e)
        {
            if(this.isEmpty()) 
            {
                Node temp = new Node(e);
                this.font = temp;
                this.tail = this.font;
            }
            else
            {
                Node temp = new Node(e);
                this.tail.next = temp;
                this.tail = temp;
            }
        }
    
        public Object deQueue()
        {
            if(this.isEmpty()) return null;
            if(this.font==this.tail) 
            {
                Node temp = this.font;
                this.font = null;
                this.tail = null;
                return temp.data;
            }
            else
            {
                Node temp= this.font;
                this.font  = temp.next;
                return temp.data;
            }
        }
    
        public static void main(String[] args)
        {
            LinkHeap<Integer> mLinkHeap = new LinkHeap<Integer>();
            for(int i=0;i<10;i++)
                mLinkHeap.enQueue(new Integer(i+1));
            while(mLinkHeap.isEmpty()==false)
            {
                System.out.print(mLinkHeap.deQueue()+"	");
            }   
        }
    }
  • 相关阅读:
    Mybatis原理
    周六上课随记
    第一次外包面试
    复习所想
    如何解决高并发下的超卖问题
    Tomcat架构解析
    即将逝去的25岁
    go 刷算法第一题——反转字符串
    JavaScript杂货
    jdk17新特性
  • 原文地址:https://www.cnblogs.com/yldf/p/11900139.html
Copyright © 2011-2022 走看看