| 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.mhhe.clrs2e.QueueArray
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 | 
protected int head
protected int tail
protected java.lang.Object[] queue
| Constructor Detail | 
public QueueArray()
public QueueArray(int size)
size - The number of slots.| Method Detail | 
public void enqueue(java.lang.Object x)
enqueue in interface Queuex - Object to be enqueued.public java.lang.Object dequeue()
dequeue in interface Queuepublic boolean isEmpty()
true if the queue is empty,
 false otherwise.
isEmpty in interface Queue
  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||