Package algs13
Class Queue<T>
java.lang.Object
algs13.Queue<T>
- All Implemented Interfaces:
Iterable<T>
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> booleandequeue()Remove and return the item on the queue least recently added.voidAdd the item to the queue.booleanisEmpty()Is the queue empty?iterator()Return an iterator that iterates over the items on the queue in FIFO order.static voidA test client.peek()Return the item least recently added to the queue.intsize()Return the number of items in the queue.voidtoGraphviz(String filename) private voidtoGraphviz(GraphvizBuilder gb, Queue.Node<T> prev, Queue.Node<T> n) toString()Return string representation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
N
-
first
-
last
-
-
Constructor Details
-
Queue
public Queue()Create an empty queue.
-
-
Method Details
-
isEmpty
Is the queue empty? -
size
Return the number of items in the queue. -
peek
Return the item least recently added to the queue.- Throws:
NoSuchElementException- if queue is empty.
-
enqueue
Add the item to the queue. -
dequeue
Remove and return the item on the queue least recently added.- Throws:
NoSuchElementException- if queue is empty.
-
toString
Return string representation. -
check
-
iterator
Return an iterator that iterates over the items on the queue in FIFO order. -
toGraphviz
-
toGraphviz
-
main
A test client.
-