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()+"	");
            }   
        }
    }
  • 相关阅读:
    BZOJ1054|HAOI2008移动玩具|广搜
    tarjan算法
    BJOJ2190|SDOI仪仗队|数论
    POJ2975|Nim|博弈论
    POJ1740|A NEW STONE GAME|博弈论
    python 单例模式
    linux 根据服务名称批量杀死进程
    python 任务计划
    python偏函数
    安装scrapy框架
  • 原文地址:https://www.cnblogs.com/yldf/p/11900139.html
Copyright © 2011-2022 走看看