structure
Class QueueList
java.lang.Object
|
+--structure.AbstractStructure
|
+--structure.AbstractLinear
|
+--structure.AbstractQueue
|
+--structure.QueueList
- All Implemented Interfaces:
- Linear, Queue, Structure
- public class QueueList
- extends AbstractQueue
- implements Queue
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 = new QueueList();
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);
}
- See Also:
QueueArray,
QueueVector
|
Field Summary |
protected List |
data
The list holding queue values in order. |
|
Constructor Summary |
QueueList()
Construct a new queue with no data. |
|
Method Summary |
void |
add(Object value)
Add a value to the tail of the queue. |
void |
clear()
Remove all the values from the queue. |
Object |
get()
Fetch the value at the head of the queue. |
boolean |
isEmpty()
Determine if the queue is empty. |
Iterator |
iterator()
Returns an iterator for traversing the structure. |
Object |
remove()
Remove a value from the head of the queue. |
int |
size()
Determine the number of elements within the queue. |
String |
toString()
Construct a string representation of the queue. |
| Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait |
data
protected List data
- The list holding queue values in order.
QueueList
public QueueList()
- Construct a new queue with no data.
add
public void add(Object value)
- Add a value to the tail of the queue.
- Specified by:
add in interface Queue
- Parameters:
value - The value added.- Postcondition:
- The value is added to the tail of the structure
- See Also:
AbstractQueue.enqueue(java.lang.Object)
remove
public Object remove()
- Remove a value from the head of the queue.
- Specified by:
remove in interface Queue
- Precondition:
- The queue is not empty
- Postcondition:
- The head of the queue is removed and returned
- Returns:
- The value actually removed.
- See Also:
AbstractQueue.dequeue()
get
public Object get()
- Fetch the value at the head of the queue.
- Specified by:
get in interface Queue
- Precondition:
- The queue is not empty
- Postcondition:
- The element at the head of the queue is returned
- Returns:
- Reference to the first value of the queue.
size
public int size()
- Determine the number of elements within the queue.
- Specified by:
size in interface Queue
- Postcondition:
- Returns the number of elements in the queue
- Returns:
- The number of elements within the queue.
clear
public void clear()
- Remove all the values from the queue.
- Specified by:
clear in interface Structure
- Postcondition:
- Removes all elements from the queue
isEmpty
public boolean isEmpty()
- Determine if the queue is empty.
- Specified by:
isEmpty in interface Structure- Overrides:
isEmpty in class AbstractStructure
- Postcondition:
- Returns true iff the queue is empty
- Returns:
- True iff the queue is empty.
iterator
public Iterator iterator()
- Description copied from interface:
Structure
- Returns an iterator for traversing the structure.
- Specified by:
iterator in interface Structure
- Following copied from interface:
structure.Structure
- Returns:
- an iterator for traversing the structure
- See Also:
AbstractIterator,
Iterator,
Enumeration,
Structure.elements()
toString
public String toString()
- Construct a string representation of the queue.
- Overrides:
toString in class Object
- Postcondition:
- Returns string representation of queue
- Returns:
- String representing the queue.