m865.datastructures
Class QueueLL<T>

java.lang.Object
  extended by m865.datastructures.AbstractQueue<T>
      extended by m865.datastructures.QueueLL<T>
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>

public class QueueLL<T>
extends AbstractQueue<T>

This class implements a Queue using a simple Linked List. Version 3.0 incorporates generics


Nested Class Summary
 class QueueLL.Link<T>
          The Linked List is built from a simple forward link.
 class QueueLL.QueueLLIterator<T>
          An iterator for a Linked List queue.
 
Field Summary
protected  QueueLL.Link<T> back
           
protected  QueueLL.Link<T> front
          The queue is implemented with a Linked List The Linked List starts with the link called top.
protected  int nItems
           
 
Fields inherited from class m865.datastructures.AbstractQueue
hash
 
Constructor Summary
QueueLL()
          Constructs a queue which uses a simple Linked List.
QueueLL(java.util.Collection<? extends T> c)
          Constructs a queue which is initialized with the objects in the specified collection
 
Method Summary
 void clear()
          Removes all the objects from this queue.
 T dequeue()
          Removes and returns the object on the top of the queue.
 void enqueue(T x)
          Enqueues an object to the back of the queue.
 boolean isEmpty()
          Determines whether the queue is empty.
 java.util.Iterator<T> iterator()
          A factory method which returns an Iterator to the collection in this queue.
static void main(java.lang.String[] args)
          This main method tests the QueueLL class to insure that the elementary functions are correct.
 T peek()
          Returns the object on the top of the queue.
 int size()
          Determines the size of this queue.
 java.lang.String toString()
          List the objects in the queue
 
Methods inherited from class m865.datastructures.AbstractQueue
add, addAll, contains, containsAll, downdateHashCode, equals, hashCode, remove, removeAll, retainAll, toArray, toArray, updateHashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

front

protected QueueLL.Link<T> front
The queue is implemented with a Linked List The Linked List starts with the link called top.


back

protected QueueLL.Link<T> back

nItems

protected int nItems
Constructor Detail

QueueLL

public QueueLL()
Constructs a queue which uses a simple Linked List.


QueueLL

public QueueLL(java.util.Collection<? extends T> c)
Constructs a queue which is initialized with the objects in the specified collection

Parameters:
c - the collection of objects to be initially pushed onto this queue.
Method Detail

enqueue

public void enqueue(T x)
Enqueues an object to the back of the queue.

Specified by:
enqueue in class AbstractQueue<T>
Parameters:
x - the object to be placed at the back of the queue.

dequeue

public T dequeue()
Removes and returns the object on the top of the queue.

Specified by:
dequeue in class AbstractQueue<T>
Returns:
the object on the top of the queue or null if the queue is empty.

peek

public T peek()
Returns the object on the top of the queue. The queue remains unchanged.

Specified by:
peek in class AbstractQueue<T>
Returns:
the object on the top of the queue or null if the queue is empty.

clear

public void clear()
Removes all the objects from this queue. This is one of the optional operations specified by the Collection Interface


isEmpty

public boolean isEmpty()
Determines whether the queue is empty.

Specified by:
isEmpty in interface java.util.Collection<T>
Overrides:
isEmpty in class AbstractQueue<T>
Returns:
true - if this collection contains no elements.

iterator

public java.util.Iterator<T> iterator()
A factory method which returns an Iterator to the collection in this queue. This iterator will walk throught the queue from the top to the bottom. It will throw a ConcurrentModificationException if the queue is altered during the iteration.

Returns:
a QueueLLIterator.

size

public int size()
Determines the size of this queue.

Returns:
the number of objects in this queue.

toString

public java.lang.String toString()
List the objects in the queue

Overrides:
toString in class AbstractQueue<T>
Returns:
a formatted string listing the objects in this queue

main

public static void main(java.lang.String[] args)
This main method tests the QueueLL class to insure that the elementary functions are correct.

Parameters:
args - optional command line arguments which will be ignored.