structure5
Class QueueList<E>

java.lang.Object
  extended by structure5.AbstractStructure<E>
      extended by structure5.AbstractLinear<E>
          extended by structure5.AbstractQueue<E>
              extended by structure5.QueueList<E>
All Implemented Interfaces:
Iterable<E>, Linear<E>, Queue<E>, Structure<E>

public class QueueList<E>
extends AbstractQueue<E>
implements Queue<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 = 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

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.
 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.
 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
equals, 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
 

Constructor Detail

QueueList

public QueueList()
Construct a new queue with no data.

Method Detail

add

public void add(E value)
Add a value to the tail of the queue.

Specified by:
add in interface Linear<E>
Specified by:
add in interface Queue<E>
Specified by:
add in interface Structure<E>
Parameters:
value - The value added.
See Also:
AbstractQueue.enqueue(E)

remove

public E remove()
Remove a value from the head of the queue.

Specified by:
remove in interface Linear<E>
Specified by:
remove in interface Queue<E>
Returns:
The value actually removed.
See Also:
AbstractQueue.dequeue()

get

public E get()
Fetch the value at the head of the queue.

Specified by:
get in interface Linear<E>
Specified by:
get in interface Queue<E>
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 Linear<E>
Specified by:
size in interface Queue<E>
Specified by:
size in interface Structure<E>
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<E>

isEmpty

public boolean isEmpty()
Determine if the queue is empty.

Specified by:
isEmpty in interface Structure<E>
Overrides:
isEmpty in class AbstractStructure<E>
Returns:
True iff the queue is empty.

iterator

public Iterator<E> iterator()
Description copied from interface: Structure
Returns an iterator for traversing the structure.

Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Structure<E>
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
Returns:
String representing the queue.