|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure5.AbstractStructure<E> structure5.AbstractLinear<E> structure5.AbstractQueue<E> structure5.QueueList<E>
public class QueueList<E>
An implementation of queues based on circular lists. 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 that resizes in constant time.
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) {QueueList
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.AbstractLinear.empty()
){ char c = ((Character)q.AbstractQueue.dequeue()
).charValue(); unicodeSum+=Character.getNumericValue(c); } System.out.println("Total Value: " + unicodeSum); }
QueueArray
,
QueueVector
Field Summary | |
---|---|
protected List<E> |
data
The list holding queue values in order. |
Constructor Summary | |
---|---|
QueueList()
Construct a new queue with no data. |
Method Summary | |
---|---|
void |
add(E value)
Add a value to the tail of the queue. |
void |
clear()
Remove all the values from the queue. |
E |
get()
Fetch the value at the head of the queue. |
boolean |
isEmpty()
Determine if the queue is empty. |
java.util.Iterator<E> |
iterator()
Returns an iterator for traversing the structure. |
E |
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 structure5.AbstractQueue |
---|
dequeue, enqueue, getFirst, peek |
Methods inherited from class structure5.AbstractLinear |
---|
empty, remove |
Methods inherited from class structure5.AbstractStructure |
---|
contains, elements, hashCode, values |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure5.Queue |
---|
dequeue, empty, enqueue, getFirst, peek |
Methods inherited from interface structure5.Structure |
---|
contains, elements, remove, values |
Field Detail |
---|
protected List<E> data
Constructor Detail |
---|
public QueueList()
Method Detail |
---|
public void add(E value)
add
in interface Linear<E>
add
in interface Queue<E>
add
in interface Structure<E>
value
- The value added.AbstractQueue.enqueue(E)
public E remove()
remove
in interface Linear<E>
remove
in interface Queue<E>
AbstractQueue.dequeue()
public E get()
get
in interface Linear<E>
get
in interface Queue<E>
public int size()
size
in interface Linear<E>
size
in interface Queue<E>
size
in interface Structure<E>
public void clear()
clear
in interface Structure<E>
public boolean isEmpty()
isEmpty
in interface Structure<E>
isEmpty
in class AbstractStructure<E>
public java.util.Iterator<E> iterator()
Structure
iterator
in interface java.lang.Iterable<E>
iterator
in interface Structure<E>
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 |