public class ArrayQueue<E> extends Object implements Queue<E>
Modifier and Type | Field and Description |
---|---|
static int |
CAPACITY
Default array capacity.
|
Constructor and Description |
---|
ArrayQueue()
Constructs an empty queue using the default array capacity.
|
ArrayQueue(int capacity)
Constructs and empty queue with the given array capacity.
|
Modifier and Type | Method and Description |
---|---|
E |
dequeue()
Removes and returns the first element of the queue.
|
void |
enqueue(E e)
Inserts an element at the rear of the queue.
|
E |
first()
Returns, but does not remove, the first element of the queue.
|
boolean |
isEmpty()
Tests whether the queue is empty.
|
int |
size()
Returns the number of elements in the queue.
|
String |
toString()
Returns a string representation of the queue as a list of elements.
|
public static final int CAPACITY
public ArrayQueue()
public ArrayQueue(int capacity)
capacity
- length of the underlying arraypublic int size()
public boolean isEmpty()
public void enqueue(E e) throws IllegalStateException
enqueue
in interface Queue<E>
e
- new element to be insertedIllegalStateException
- if the array storing the elements is fullpublic E first()
public E dequeue()