queue的referrence的java实现

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

 9public 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
 1package queue;
 2
 3import list.*;
 4
 5/**
 6 * This class is the implementation of IQueue interface
 7 * 
 8 * @author 
 9 * @version 1.0
10 */

11public 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
posted @ 2007-12-03 06:37  N/A2011  阅读(357)  评论(0编辑  收藏  举报