|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Queue<ELTTYPE>
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(ELTTYPE value)
Add a value to the tail of the queue. |
ELTTYPE |
dequeue()
Remove a value from the head of the queue. |
boolean |
empty()
Returns true iff the queue is empty. |
void |
enqueue(ELTTYPE value)
Add a value to the tail of the queue. |
ELTTYPE |
get()
Fetch the value at the head of the queue. |
ELTTYPE |
getFirst()
Fetch the value at the head of the queue. |
ELTTYPE |
peek()
Fetch the value at the head of the queue. |
ELTTYPE |
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 |
---|
void add(ELTTYPE value)
add
in interface Linear<ELTTYPE>
add
in interface Structure<ELTTYPE>
value
- The value added.enqueue(ELTTYPE)
void enqueue(ELTTYPE value)
value
- The value to be added.ELTTYPE remove()
remove
in interface Linear<ELTTYPE>
dequeue()
ELTTYPE dequeue()
ELTTYPE getFirst()
ELTTYPE get()
get
in interface Linear<ELTTYPE>
ELTTYPE peek()
boolean empty()
empty
in interface Linear<ELTTYPE>
int size()
size
in interface Linear<ELTTYPE>
size
in interface Structure<ELTTYPE>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |