Class Queue

java.lang.Object
  |
  +--Queue

public class Queue
extends java.lang.Object

A Queue represents a first-in-first-out (FIFO) data structure: the item deleted is always the item which has been in the queue the longest. A total of five operations are allowed on a queue:

The toString method has also been defined.

When a queue is first created, it contains no items.


Field Summary
private  ListNode back
           
private  ListNode front
           
 
Constructor Summary
Queue()
          Creates an empty Queue.
 
Method Summary
 boolean contains(java.lang.Object obj)
          Tests if the specified object is in the queue.
 java.lang.Object dequeue()
          Removes the object from the front of the queue and returns that object as the value of this method.
 void enqueue(java.lang.Object item)
          Adds a new item to the end of the Queue.
 boolean isEmpty()
          Tests if this Queue is empty
 java.lang.Object peek()
          Return the object at the front of this queue.
 java.lang.String toString()
          Returns a String representation of the queue.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

front

private ListNode front

back

private ListNode back
Constructor Detail

Queue

public Queue()
Creates an empty Queue.
Method Detail

isEmpty

public boolean isEmpty()
Tests if this Queue is empty
Returns:
true if and only if the Queue contains no items; false otherwise

enqueue

public void enqueue(java.lang.Object item)
Adds a new item to the end of the Queue.
Parameters:
item - the item to put at the end of the Queue

dequeue

public java.lang.Object dequeue()
Removes the object from the front of the queue and returns that object as the value of this method.
Returns:
the item removed from the front of the queue
Throws:
java.util.NoSuchElementException - if this queue is empty

peek

public java.lang.Object peek()
Return the object at the front of this queue.
Returns:
the item at the front of the queue
Throws:
java.util.NoSuchElementException - if this queue is empty

toString

public java.lang.String toString()
Returns a String representation of the queue. Uses the String representation of each object in the queue
Returns:
a String representation of the queue
Overrides:
toString in class java.lang.Object

contains

public boolean contains(java.lang.Object obj)
Tests if the specified object is in the queue. Uses the equals method of the object
Parameters:
obj - the object that may be in the queue
Returns:
true if and only if the specified object is the same as a component of this queue, as determined by the equals method; false otherwise