net.datastructures
Class NodeQueue<E>

java.lang.Object
  extended by net.datastructures.NodeQueue<E>
All Implemented Interfaces:
Queue<E>

public class NodeQueue<E>
extends java.lang.Object
implements Queue<E>

Realization of a queue by means of a singly-linked list of nodes. All operations are performed in constant time.

Author:
Roberto Tamassia

Constructor Summary
NodeQueue()
          Creates an empty queue.
 
Method Summary
 E dequeue()
          Removes the element at the front of the queue.
 void enqueue(E elem)
          Inserts an element at the rear of the queue.
 E front()
          Inspects the element at the front of the queue.
 boolean isEmpty()
          Returns whether the queue is empty.
static void main(java.lang.String[] args)
          Test program that performs a series of operations on on a queue and prints the operation performed, the returned element and the content of the stack after each operation.
 int size()
          Returns the number of elements in the queue.
static void status(Queue Q, java.lang.String op, java.lang.Object element)
          Prints information about an operation and the queue.
 java.lang.String toString()
          Return string equivalent of the queue
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeQueue

public NodeQueue()
Creates an empty queue.

Method Detail

size

public int size()
Returns the number of elements in the queue.

Specified by:
size in interface Queue<E>
Returns:
number of elements in the queue.

isEmpty

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

Specified by:
isEmpty in interface Queue<E>
Returns:
true if the queue is empty, false otherwise.

enqueue

public void enqueue(E elem)
Inserts an element at the rear of the queue.

Specified by:
enqueue in interface Queue<E>
Parameters:
element - new element to be inserted.

front

public E front()
        throws EmptyQueueException
Inspects the element at the front of the queue.

Specified by:
front in interface Queue<E>
Returns:
element at the front of the queue.
Throws:
EmptyQueueException - if the queue is empty.

dequeue

public E dequeue()
          throws EmptyQueueException
Removes the element at the front of the queue.

Specified by:
dequeue in interface Queue<E>
Returns:
element removed.
Throws:
EmptyQueueException - if the queue is empty.

toString

public java.lang.String toString()
Return string equivalent of the queue

Overrides:
toString in class java.lang.Object

status

public static void status(Queue Q,
                          java.lang.String op,
                          java.lang.Object element)
Prints information about an operation and the queue.

Parameters:
op - operation performed
element - element returned by the operation

main

public static void main(java.lang.String[] args)
Test program that performs a series of operations on on a queue and prints the operation performed, the returned element and the content of the stack after each operation.