Java Reference
In-Depth Information
Display 15.29
A
Queue
Class
(part 2 of 2)
25
/**
26
Adds a String to the back of the queue.
27
*/
28
public void
addToBack(String itemName)
<The definition of this method is defined in Self-Test Exercise 18.>
29
public boolean
isEmpty( )
30 {
31
return
(front ==
null
);
32 }
33
public void
clear( )
34 {
35 front =
null
;
36 back =
null
;
37 }
38
/**
39
Returns the String in the front of the queue.
40
Returns null if queue is empty.
41
*/
42
public
String whoIsNext( )
43 {
44
if
(front ==
null
)
45
return null
;
46
else
47
return
front.item;
48 }
49
50
/**
51
Removes a String from the front of the queue.
52
Returns false if the list is empty.
53
*/
54
public boolean
removeFront( )
55 {
56
if
(front !=
null
)
57 {
58 front = front.link;
59
return true
;
60 }
61
else
62
return false
;
63 }
64 }