jdsl.simple.ref
Class ArrayQueue
java.lang.Object
|
+--jdsl.simple.ref.ArrayQueue
- public class ArrayQueue
- extends java.lang.Object
- implements Queue
Implementation of the Queue interface using an array. The queue can store
at most a given number of elements; if the user tries to insert more than that,
number, an exception is thrown.
- Author:
- Natasha Gelfand
|
Field Summary |
static int |
CAPACITY
Default maximum capacity of the queue. |
|
Constructor Summary |
ArrayQueue()
This constructor initializes the queue with the default capacity
specified by the CAPACITY constant. |
ArrayQueue(int cap)
This constructor initializes the queue with the capacity specified by
the user. |
|
Method Summary |
java.lang.Object |
dequeue()
Removes the element which is the first element in the queue and
return a reference to it. |
void |
enqueue(java.lang.Object obj)
Inserts a new object at the rear of the queue. |
java.lang.Object |
front()
Return the element which is the first in the queue |
boolean |
isEmpty()
This function returns true if and only if the queue is empty |
int |
size()
Return the size of the queue, that is the number of elements it has. |
| Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
CAPACITY
public static final int CAPACITY
- Default maximum capacity of the queue.
ArrayQueue
public ArrayQueue()
- This constructor initializes the queue with the default capacity
specified by the CAPACITY constant.
ArrayQueue
public ArrayQueue(int cap)
- This constructor initializes the queue with the capacity specified by
the user.
- Parameters:
cap - Capacity of the queue
size
public int size()
- Return the size of the queue, that is the number of elements it has.
- Specified by:
- size in interface Queue
- Returns:
- Number of elements in the queue
isEmpty
public boolean isEmpty()
- This function returns true if and only if the queue is empty
- Specified by:
- isEmpty in interface Queue
- Returns:
- true if the queue is empty, false otherwise
front
public java.lang.Object front()
throws QueueEmptyException
- Return the element which is the first in the queue
- Specified by:
- front in interface Queue
- Returns:
- The first queue element
dequeue
public java.lang.Object dequeue()
throws QueueEmptyException
- Removes the element which is the first element in the queue and
return a reference to it.
- Specified by:
- dequeue in interface Queue
- Returns:
- First element in the queue
enqueue
public void enqueue(java.lang.Object obj)
- Inserts a new object at the rear of the queue.
- Specified by:
- enqueue in interface Queue
- Parameters:
obj - Object to insert