|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface describing a first-in, first-out structure. Values are added at the tail, and removed from the head. Queues are typically used to process values in the order that they appear and to store the state of a buffered object. The structure package provides several implementations of the Queue interface, each of which has its particular strengths and weaknesses.
Example usage:
To compute the sum of the unicode value of every character in the standard input we could use the following:
public static void main(String[] arguments) {Queue
q = newQueueList()
; int unicodeSum = 0; if(arguments.length > 0){ for(int i=0; i < arguments.length; i++){ for(int j=0; j < arguments[i].length(); j++){ q.enqueue(new Character(arguments[i].charAt(j)))
; } } } while(!q.empty()
){ char c = ((Character)q.dequeue()
).charValue(); unicodeSum+=Character.getNumericValue(c); } System.out.println("Total Value: " + unicodeSum); }
Stack
,
AbstractQueue
,
QueueArray
,
QueueVector
,
QueueList
Method Summary | |
void |
add(Object value)
Add a value to the tail of the queue. |
Object |
dequeue()
Remove a value from the head of the queue. |
boolean |
empty()
Returns true iff the queue is empty. |
void |
enqueue(Object value)
Add a value to the tail of the queue. |
Object |
get()
Fetch the value at the head of the queue. |
Object |
getFirst()
Fetch the value at the head of the queue. |
Object |
peek()
Fetch the value at the head of the queue. |
Object |
remove()
Remove a value form the head of the queue. |
int |
size()
Returns the number of elements in the queue. |
Methods inherited from interface structure.Structure |
clear, contains, elements, isEmpty, iterator, remove, values |
Method Detail |
public void add(Object value)
add
in interface Linear
value
- The value added.enqueue(java.lang.Object)
public void enqueue(Object value)
value
- The value to be added.public Object remove()
remove
in interface Linear
dequeue()
public Object dequeue()
public Object getFirst()
public Object get()
get
in interface Linear
public Object peek()
public boolean empty()
empty
in interface Linear
public int size()
size
in interface Linear
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |