Class MyQueue

java.lang.Object
  |
  +--MyQueue
All Implemented Interfaces:
Queue
Direct Known Subclasses:
MyPriorityQueue

public class MyQueue
extends Object
implements Queue

An implementation of a Queue.

Currently uses a circular reference-based linked-list implementation, so adding and removing elements are both O(1) (order of 1) operations.

Version:
02 Mar 2005
Author:
Zach Tomaszewski

Field Summary
protected  Node tail
           
 
Constructor Summary
MyQueue()
           
 
Method Summary
 Object dequeue()
          Removes an element from the front of this queue and returns it.
 boolean empty()
          Returns whether this queue is empty.
 void enqueue(Object obj)
          Adds the given object to the end of this queue.
 Object front()
          Returns the element currently stored at the front of this queue, but does not remove that element.
 String toString()
          Returns a String representation of this queue, with the top as the first item in the list.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tail

protected Node tail
Constructor Detail

MyQueue

public MyQueue()
Method Detail

empty

public boolean empty()
Returns whether this queue is empty.
Specified by:
empty in interface Queue
Returns:
true is the queue is empty; false if it contains any elements.

enqueue

public void enqueue(Object obj)
Adds the given object to the end of this queue.
Specified by:
enqueue in interface Queue

dequeue

public Object dequeue()
               throws QueueEmptyException
Removes an element from the front of this queue and returns it.
Specified by:
dequeue in interface Queue
Returns:
The element removed from the queue
Throws:
QueueEmptyException - if the queue is empty

front

public Object front()
             throws QueueEmptyException
Returns the element currently stored at the front of this queue, but does not remove that element. (That is, the queue is unaffected by this operation.)
Specified by:
front in interface Queue
Throws:
QueueEmptyException - if this queue is empty

toString

public String toString()
Returns a String representation of this queue, with the top as the first item in the list.
Overrides:
toString in class Object