|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.AbstractStructure<ELTTYPE> structure.AbstractLinear<ELTTYPE> structure.AbstractQueue<ELTTYPE> structure.QueueVector<ELTTYPE>
public class QueueVector<ELTTYPE>
An implementation of queues based on vectors. The head of the queue is stored at the head of the list, allowing the queue to grow and shrink in constant time. This queue implementation is ideal for applications that require a dynamically resizable queue which occasionally takes a time proportional to the its length to expand.
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) {QueueVector
q = newQueueVector()
; 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.AbstractLinear.empty()
){ char c = ((Character)q.AbstractQueue.dequeue()
).charValue(); unicodeSum+=Character.getNumericValue(c); } System.out.println("Total Value: " + unicodeSum); }
QueueArray
,
QueueList
Constructor Summary | |
---|---|
QueueVector()
Construct an empty queue |
|
QueueVector(int size)
Constructs an empty queue with an initial allocation of size. |
Method Summary | |
---|---|
void |
add(ELTTYPE value)
Add a value to the tail of the queue |
void |
clear()
Remove all the values from the queue. |
ELTTYPE |
get()
Fetch the value at the head of the queue. |
boolean |
isEmpty()
Determine if the queue is empty. |
java.util.Iterator |
iterator()
Returns an iterator for traversing the structure. |
ELTTYPE |
remove()
Remove a value from the head of the queue |
int |
size()
Determine the number of elements within the queue. |
java.lang.String |
toString()
Construct a string representation of the queue. |
Methods inherited from class structure.AbstractQueue |
---|
dequeue, enqueue, getFirst, peek |
Methods inherited from class structure.AbstractLinear |
---|
empty, remove |
Methods inherited from class structure.AbstractStructure |
---|
contains, elements, hashCode, values |
Methods inherited from class java.lang.Object |
---|
equals, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure.Queue |
---|
dequeue, empty, enqueue, getFirst, peek |
Methods inherited from interface structure.Structure |
---|
contains, elements, remove, values |
Constructor Detail |
---|
public QueueVector()
public QueueVector(int size)
size
- Approximate largest queue size needed.Method Detail |
---|
public void add(ELTTYPE value)
add
in interface Linear<ELTTYPE>
add
in interface Queue<ELTTYPE>
add
in interface Structure<ELTTYPE>
value
- The value added.Queue.enqueue(ELTTYPE)
public ELTTYPE remove()
remove
in interface Linear<ELTTYPE>
remove
in interface Queue<ELTTYPE>
AbstractQueue.dequeue()
public ELTTYPE get()
get
in interface Linear<ELTTYPE>
get
in interface Queue<ELTTYPE>
public int size()
size
in interface Linear<ELTTYPE>
size
in interface Queue<ELTTYPE>
size
in interface Structure<ELTTYPE>
public void clear()
clear
in interface Structure<ELTTYPE>
public boolean isEmpty()
isEmpty
in interface Structure<ELTTYPE>
isEmpty
in class AbstractStructure<ELTTYPE>
public java.util.Iterator iterator()
Structure
iterator
in interface java.lang.Iterable<ELTTYPE>
iterator
in interface Structure<ELTTYPE>
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |