queue的referrence的java实现

 
 1 package  queue;
 2
 3 /** */ /**
 4 * This is queue interface
 5 * 
 6 * @author 
 7 * @version 1.0
 8 */

 9 public   interface  IQueue
10 {
11    /** *//**
12     * Method that will push the element specified by the parameter into the
13     * queue
14     * 
15     * @param object, the element that will be push into the queue
16     */

17    public void enQueue(Object object);
18    
19    /** *//**
20     * Method that will return the first element in the queue and also pull the
21     * element out of the stack, if there is no element left, it will return
22     * null
23     * 
24     * @return object, the last element in the queue
25     */

26    public Object deQueue();
27    
28    /** *//**
29     * Method that will check if the queue is empty, if it is empty,it will
30     * return true,else it will return false
31     * 
32     * @return boolean that indicates if the queue is empty or not
33     */

34    public boolean isEmpty();
35}

36
 1 package  queue;
 2
 3 import  list. * ;
 4
 5 /** */ /**
 6 * This class is the implementation of IQueue interface
 7 * 
 8 * @author 
 9 * @version 1.0
10 */

11 public   class  Queue  implements  IQueue
12 {
13    /** *//**
14     * Attributes
15     */

16    private DoublyLinkedList dll;
17    
18    /** *//**
19     * Constructor
20     */

21    public Queue()
22    {
23        this.dll = new DoublyLinkedList();
24    }

25    
26    /**//*
27     * (non-Javadoc)
28     * 
29     * @see queue.IQueue#enQueue(java.lang.Object)
30     */

31    public void enQueue(Object object)
32    {
33        this.dll.add(object);
34    }

35    
36    /**//*
37     * (non-Javadoc)
38     * 
39     * @see queue.IQueue#deQueue()
40     */

41    public Object deQueue()
42    {
43        if(this.dll.isEmpty())
44        {
45            return null;
46        }

47        else
48        {
49            Object object = this.dll.get(0);
50            this.dll.remove(0);
51            return object;
52        }

53    }

54    
55    /**//*
56     * (non-Javadoc)
57     * 
58     * @see queue.IQueue#isEmpty()
59     */

60    public boolean isEmpty()
61    {
62        return dll.isEmpty();
63    }

64}

65

转载于:https://www.cnblogs.com/aspxphpjsprb/archive/2007/12/03/980412.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值