com.mhhe.clrs2e
Class QueueArray

java.lang.Object
  |
  +--com.mhhe.clrs2e.QueueArray
All Implemented Interfaces:
Queue

public class QueueArray
extends java.lang.Object
implements Queue

Implements a queue from page 203 of Introduction to Algorithms, Second edition.

This implementation does not check for overflow or underflow, since Exercise 10.1-4 asks you to supply code checking for these conditions.


Field Summary
protected  int head
          The index of the head of the queue.
protected  java.lang.Object[] queue
          The array implementing the queue.
protected  int tail
          The index at which the next object will be added.
 
Constructor Summary
QueueArray()
          Creates an empty queue with 100 slots.
QueueArray(int size)
          Creates an empty queue with a given number of slots.
 
Method Summary
 java.lang.Object dequeue()
          Returns and removes the object at the head of the queue.
 void enqueue(java.lang.Object x)
          Adds an object to the tail of the queue.
 boolean isEmpty()
          Returns true if the queue is empty, false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

head

protected int head
The index of the head of the queue.


tail

protected int tail
The index at which the next object will be added.


queue

protected java.lang.Object[] queue
The array implementing the queue.

Constructor Detail

QueueArray

public QueueArray()
Creates an empty queue with 100 slots.


QueueArray

public QueueArray(int size)
Creates an empty queue with a given number of slots.

Parameters:
size - The number of slots.
Method Detail

enqueue

public void enqueue(java.lang.Object x)
Adds an object to the tail of the queue. Performs no overflow checking.

Specified by:
enqueue in interface Queue
Parameters:
x - Object to be enqueued.

dequeue

public java.lang.Object dequeue()
Returns and removes the object at the head of the queue. Performs no underflow checking.

Specified by:
dequeue in interface Queue

isEmpty

public boolean isEmpty()
Returns true if the queue is empty, false otherwise.

Specified by:
isEmpty in interface Queue