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()+"	");
            }   
        }
    }
  • 相关阅读:
    循环排序总结
    # 区间合并总结
    快慢指针
    #双指针总结
    滑动窗口总结
    leetcode 第 221 场周赛
    剑指 Offer 07. 重建二叉树
    leetcode 406. 根据身高重建队列
    [JLOI2014]松鼠的新家 T22 D71
    软件包管理器 T21 D71
  • 原文地址:https://www.cnblogs.com/yldf/p/11900139.html
Copyright © 2011-2022 走看看