Package com.zybooks.dsaj.stackqueue
Class ArrayQueue<E>
java.lang.Object
com.zybooks.dsaj.stackqueue.ArrayQueue<E>
- Type Parameters:
- E- the element type
- All Implemented Interfaces:
- Queue<E>
Implementation of the queue ADT using a fixed-length array. All
 operations are performed in constant time. An exception is thrown
 if an enqueue operation is attempted when the size of the queue is
 equal to the length of the array.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs an empty queue using the default array capacity.ArrayQueue(int capacity) Constructs and empty queue with the given array capacity.
- 
Method SummaryModifier and TypeMethodDescriptiondequeue()Removes and returns the first element of the queue.voidAdds an element at the rear of the queue.first()Returns, but does not remove, the first element of the queue.booleanisEmpty()Tests whether the queue is empty.intsize()Returns the number of elements in the queue.toString()Returns a string representation of the queue as a list of elements.
- 
Field Details- 
CAPACITYpublic static final int CAPACITYDefault array capacity.- See Also:
 
 
- 
- 
Constructor Details- 
ArrayQueuepublic ArrayQueue()Constructs an empty queue using the default array capacity.
- 
ArrayQueuepublic ArrayQueue(int capacity) Constructs and empty queue with the given array capacity.- Parameters:
- capacity- length of the underlying array
 
 
- 
- 
Method Details- 
sizepublic int size()Returns the number of elements in the queue.
- 
isEmptypublic boolean isEmpty()Tests whether the queue is empty.
- 
enqueueAdds an element at the rear of the queue. This method runs in O(1) time.- Specified by:
- enqueuein interface- Queue<E>
- Parameters:
- e- new element to be added
- Throws:
- IllegalStateException- if the array storing the elements is full
 
- 
firstReturns, but does not remove, the first element of the queue.
- 
dequeueRemoves and returns the first element of the queue.
- 
toStringReturns a string representation of the queue as a list of elements. This method runs in O(n) time, where n is the size of the queue.
 
-