ObjectQueue<Item>
public class Queue<Item>
The Queue class represents a first-in-first-out (FIFO) queue of generic items. It supports the usual enqueue and dequeue operations, along with methods for peeking at the top item, testing if the queue is empty, and iterating through the items in FIFO order.
All queue operations except iteration are constant time.
For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor Summary | |
|---|---|
Queue()
Create an empty queue. |
|
| Method Summary | |
|---|---|
Item |
dequeue()
Remove and return the item on the queue least recently added. |
void |
enqueue(Item item)
Add the item to the queue. |
boolean |
isEmpty()
Is the queue empty? |
java.util.Iterator<Item> |
iterator()
Return an iterator that iterates over the items on the queue in FIFO order. |
static void |
main(String[] args)
A test client. |
Item |
peek()
Return the item least recently added to the queue. |
int |
size()
Return the number of items in the queue. |
String |
toString()
Return string representation. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Queue()
| Method Detail |
|---|
public boolean isEmpty()
public int size()
public Item peek()
public void enqueue(Item item)
public Item dequeue()
public String toString()
toString in class Objectpublic java.util.Iterator<Item> iterator()
iterator in interface Iterable<Item>public static void main(String[] args)