csc241.samples.Queue
Class dynamicQueue

java.lang.Object
  |
  +--csc241.samples.Queue.dynamicQueue
All Implemented Interfaces:
Queue

public class dynamicQueue
extends java.lang.Object
implements Queue

~mohammad/public_html/classes/csc241/Queue/dynamicQueue.java This version implements Queue using a linked list. The concept here is unlike anything you have done before. It is important to understand object refernences. A Queue has two components, 'front_' reference to the node holding the element in front and 'back_' reference to the node holding the element in the back. We remove from front and add to the back in our enqueue and dequeue, resepectively. Just like fixedQueue, all methods have implementation.


Constructor Summary
dynamicQueue()
          construct a dynamicQueue
 
Method Summary
 void dequeue()
          remove an element from the front of the queue.
 boolean empty()
          return true if queue is empty, otherwise, return false
 void enqueue(java.lang.Object x)
          add an element to the back of the queue.
 boolean full()
          return true if queue is full, otherwise, return false
 java.lang.Object peek()
          return value - the object in front of the queue; null if queue is empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

dynamicQueue

public dynamicQueue()
construct a dynamicQueue

Method Detail

empty

public boolean empty()
return true if queue is empty, otherwise, return false

Specified by:
empty in interface Queue

full

public boolean full()
return true if queue is full, otherwise, return false

Specified by:
full in interface Queue

enqueue

public void enqueue(java.lang.Object x)
             throws queueException
add an element to the back of the queue.
x - the Object to be added

Specified by:
enqueue in interface Queue
Throws:
- - Exception if queue is full.
queueException

dequeue

public void dequeue()
             throws queueException
remove an element from the front of the queue.

Specified by:
dequeue in interface Queue
Throws:
- - Exception if queue is empty.
queueException

peek

public java.lang.Object peek()
return value - the object in front of the queue; null if queue is empty.

Specified by:
peek in interface Queue