|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Queue<E>
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); }
structure.Stack
,
AbstractQueue
,
QueueArray
,
QueueVector
,
QueueList
Method Summary | |
---|---|
void |
add(E value)
Add a value to the tail of the queue. |
E |
dequeue()
Remove a value from the head of the queue. |
boolean |
empty()
Returns true iff the queue is empty. |
void |
enqueue(E value)
Add a value to the tail of the queue. |
E |
get()
Fetch the value at the head of the queue. |
E |
getFirst()
Fetch the value at the head of the queue. |
E |
peek()
Fetch the value at the head of the queue. |
E |
remove()
Remove a value form the head of the queue. |
int |
size()
Returns the number of elements in the queue. |
Methods inherited from interface structure5.Structure |
---|
clear, contains, elements, isEmpty, iterator, remove, values |
Method Detail |
---|
void add(E value)
add
in interface Linear<E>
add
in interface Structure<E>
value
- The value added.enqueue(E)
void enqueue(E value)
value
- The value to be added.E remove()
remove
in interface Linear<E>
dequeue()
E dequeue()
E getFirst()
E get()
get
in interface Linear<E>
E peek()
boolean empty()
empty
in interface Linear<E>
int size()
size
in interface Linear<E>
size
in interface Structure<E>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |