datastructures

net.datastructures
Class NodeQueue

java.lang.Object
  extended bynet.datastructures.NodeQueue
All Implemented Interfaces:
Queue

public class NodeQueue
extends Object
implements Queue

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 head
           
protected  int size
           
protected  Node tail
           
 
Constructor Summary
NodeQueue()
          Creates an empty queue.
 
Method Summary
 Object dequeue()
          Removes the element at the front of the queue.
 void enqueue(Object obj)
          Inserts an element at the rear of the queue.
 Object front()
          Inspects the element at the front of the queue.
 boolean isEmpty()
          Returns whether the queue is empty.
 int size()
          Returns the number of elements in 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 head

tail

protected Node 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
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
Returns:
true if the queue is empty, false otherwise.

enqueue

public void enqueue(Object obj)
Description copied from interface: Queue
Inserts an element at the rear of the queue.

Specified by:
enqueue in interface Queue
Parameters:
obj - new element to be inserted.

front

public Object front()
             throws EmptyQueueException
Description copied from interface: Queue
Inspects the element at the front of the queue.

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

dequeue

public Object dequeue()
               throws EmptyQueueException
Description copied from interface: Queue
Removes the element at the front of the queue.

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

toString

public String toString()

datastructures