net.datastructures - version 5.0

net.datastructures
Class NodeQueue<E>

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

public class NodeQueue<E>
extends 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

Field Summary
protected  Node<E> head
           
protected  int size
           
protected  Node<E> tail
           
 
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(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, String op, Object element)
          Prints information about an operation and the queue.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

head

protected Node<E> head

tail

protected Node<E> tail

size

protected int size
Constructor Detail

NodeQueue

public NodeQueue()
Creates an empty queue.

Method Detail

size

public int size()
Description copied from interface: Queue
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()
Description copied from interface: Queue
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)
Description copied from interface: Queue
Inserts an element at the rear of the queue.

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

front

public E front()
        throws EmptyQueueException
Description copied from interface: Queue
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
Description copied from interface: Queue
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 String toString()
Overrides:
toString in class Object

status

public static void status(Queue Q,
                          String op,
                          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(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.


net.datastructures - version 5.0