2 import java
.util
.Enumeration
;
7 Queue_Node head_
= null;
8 Queue_Node tail_
= null;
10 private int length_
= 0;
16 public Enumeration
forward_iterator()
18 return new Queue_Iterator(this, Queue_Iterator
.FORWARD
);
21 public Enumeration
reverse_iterator()
23 return new Queue_Iterator(this, Queue_Iterator
.REVERSE
);
26 public void enqueue_tail(Object new_data
)
28 Queue_Node new_node
= new Queue_Node(new_data
);
37 new_node
.prev_
= tail_
;
38 tail_
.next_
= new_node
;
45 public void enqueue_head(Object new_data
)
47 Queue_Node new_node
= new Queue_Node(new_data
);
56 new_node
.next_
= head_
;
57 head_
.prev_
= new_node
;
64 public Object
dequeue_head()
66 Object return_value
= null;
70 else if (tail_
== head_
)
72 return_value
= head_
.data_
;
78 return_value
= head_
.data_
;
88 public Object
dequeue_tail()
90 Object return_value
= null;
94 else if (tail_
== head_
)
96 return_value
= tail_
.data_
;
102 return_value
= tail_
.data_
;
136 public Queue_Node prev_
= null;
137 public Queue_Node next_
= null;
140 public Queue_Node(Object data
)
146 class Queue_Iterator
implements Enumeration
148 public static final boolean FORWARD
= true;
149 public static final boolean REVERSE
= false;
151 private Queue queue_
;
152 private Queue_Node queue_ptr_
;
153 private boolean direction_
= FORWARD
;
155 public Queue_Iterator(Queue queue
)
158 queue_ptr_
= queue
.head_
;
161 public Queue_Iterator(Queue queue
, boolean direction
)
164 direction_
= direction
;
167 queue_ptr_
= queue_
.head_
;
169 queue_ptr_
= queue_
.tail_
;
172 public Object
nextElement()
174 Object data
= queue_ptr_
.data_
;
177 queue_ptr_
= queue_ptr_
.next_
;
179 queue_ptr_
= queue_ptr_
.prev_
;
184 public boolean hasMoreElements()
186 return queue_ptr_
!= null;