Package com.zybooks.dsaj.stackqueue
Class LinkedDeque<E>
java.lang.Object
com.zybooks.dsaj.stackqueue.LinkedDeque<E>
- Type Parameters:
E
- the element type
- All Implemented Interfaces:
Deque<E>
Realization of a double-ended queue as an adaptation of a DoublyLinkedList.
All operations are performed in constant time.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an element at the front of the queue.void
Adds an element at the back of the queue.first()
Returns, but does not remove, the first element of the queue.boolean
isEmpty()
Tests whether the queue is empty.last()
Returns, but does not remove, the last element of the queue.Removes and returns the first element of the queue.Removes and returns the last element of the queue.int
size()
Returns the number of elements in the queue.toString()
Produces a string representation of the contents of the queue.
-
Constructor Details
-
LinkedDeque
public LinkedDeque()Constructs an initially empty queue.
-
-
Method Details
-
size
public int size()Returns the number of elements in the queue. -
isEmpty
public boolean isEmpty()Tests whether the queue is empty. -
first
Returns, but does not remove, the first element of the queue. -
last
Returns, but does not remove, the last element of the queue. -
addFirst
Adds an element at the front of the queue. -
addLast
Adds an element at the back of the queue. -
removeFirst
Removes and returns the first element of the queue.- Specified by:
removeFirst
in interfaceDeque<E>
- Returns:
- element removed (or null if empty)
-
removeLast
Removes and returns the last element of the queue.- Specified by:
removeLast
in interfaceDeque<E>
- Returns:
- element removed (or null if empty)
-
toString
Produces a string representation of the contents of the queue. (from front to back). This exists for debugging purposes only.
-