Java Reference
In-Depth Information
The
ListQueue
class is similar to the
ListStack
class. The
ListQueue
class skel-
eton is given in Figure 16.23. The only new thing here is that we maintain two ref-
erences instead of one. Figure 16.24 shows the constructors for the
ListQueue
class.
1
package weiss.nonstandard;
2
3
// ListQueue class
4
//
5
// CONSTRUCTION: with no initializer
6
//
7
// ******************PUBLIC OPERATIONS*********************
8
// void enqueue( x ) --> Insert x
9
// AnyType getFront( ) --> Return least recently inserted item
10
// AnyType dequeue( ) --> Return and remove least recent item
11
// boolean isEmpty( ) --> Return true if empty; else false
12
// void makeEmpty( ) --> Remove all items
13
// ******************ERRORS********************************
14
// getFront or dequeue on empty queue
15
16
public class ListQueue<AnyType>
17
{
18
public ListQueue( )
19
{ /* Figure 16.24 */ }
20
public boolean isEmpty( )
21
{ /* Figure 16.27 */ }
22
public void enqueue( AnyType x )
23
{ /* Figure 16.25 */ }
24
public AnyType dequeue( )
25
{ /* Figure 16.25 */ }
26
public AnyType getFront( )
27
{ /* Figure 16.27 */ }
28
public void makeEmpty( )
29
{ /* Figure 16.27 */ }
30
31
private ListNode<AnyType> front;
32
private ListNode<AnyType> back;
33
}
figure 16.23
Skeleton for the
linked list-based
queue class
1
/**
2
* Construct the queue.
3
*/
4
public ListQueue( )
5
{
6
front = back = null;
7
}
figure 16.24
Constructor for the
linked list-based
ListQueue
class
Search WWH ::
Custom Search