Package examples
Interface Queue<T>
public interface Queue<T>
-
Method Summary
Modifier and Type Method Description intcapacity()Returns the number of available spaces left in the queue.Tdequeue()Retrieves and removes the element at the head of the queue.voidenqueue(T e)Adds an element to the end of the queue.Tpeek()Retrieves (but does not remove) the element at the head of the queue.voidreset()Remove all items from the queue and reset the capacity to the initial maximum amount.
-
Method Details
-
capacity
int capacity()Returns the number of available spaces left in the queue.- Returns:
- how many additional items the queue can hold.
-
enqueue
Adds an element to the end of the queue.- Parameters:
e- the element to add to this collection- Throws:
IllegalStateException- if the queue cannot hold additional items
-
dequeue
T dequeue()Retrieves and removes the element at the head of the queue.- Returns:
- the least-recently added element.
- Throws:
NoSuchElementException- if the queue is empty
-
peek
T peek()Retrieves (but does not remove) the element at the head of the queue.- Returns:
- the least-recently added element.
- Throws:
NoSuchElementException- if the queue is empty
-
reset
void reset()Remove all items from the queue and reset the capacity to the initial maximum amount.
-