public class CircularQueue
extends Object
Modifier and Type | Field and Description |
---|---|
private int |
bottom
Points to the current bottom entry
|
private int |
count
Number of entries currently in the queue
|
private Object[] |
entries
The current queue entries
|
private int |
maxSize
Max # of entries in the queue
|
static Tester |
tester
Basic regression test
|
Constructor and Description |
---|
CircularQueue(int maxSize)
Construct a queue that can hold, at most, 'maxSize' entries.
|
Modifier and Type | Method and Description |
---|---|
void |
addHead(Object obj)
Add an object to the start of the queue.
|
void |
addTail(Object obj)
Add an object to the end of the queue.
|
void |
clear()
Removes all entries from the queue.
|
int |
count()
Counts how many items are currently in the queue
|
boolean |
isEmpty()
Checks whether the queue is currently empty
|
boolean |
isFull()
Checks whether the queue is currently full
|
Object |
peek(int distance)
Peek into the queue but do not remove the object.
|
Object |
removeHead()
Removes and returns the first object in the queue.
|
Object |
removeTail()
Removes and returns the last object in the queue.
|
private int maxSize
private Object[] entries
private int bottom
private int count
public static final Tester tester
public CircularQueue(int maxSize)
maxSize
- Maximum number of entries in the queuepublic final void addTail(Object obj)
obj
- Object to add.public final void addHead(Object obj)
obj
- Object to add.public final Object removeHead()
public final Object removeTail()
public final Object peek(int distance)
distance
- How far to peek into the queue (zero means peek at the
head, one to peek at head+1, etc.)public final void clear()
public final int count()
public final boolean isEmpty()
public final boolean isFull()