deQueue - Notes By ShariqSP
Deque Interface in Java
The Deque
interface in Java represents a double-ended queue, which allows insertion and removal of elements from both ends. It extends the Queue
interface and provides additional methods for insertion and removal at both ends.
Methods:
- addFirst(E element): Inserts the specified element at the front of the deque.
- addLast(E element): Inserts the specified element at the end of the deque.
- removeFirst(): Removes and returns the first element of the deque.
- removeLast(): Removes and returns the last element of the deque.
- getFirst(): Retrieves, but does not remove, the first element of the deque.
- getLast(): Retrieves, but does not remove, the last element of the deque.
- isEmpty(): Returns true if the deque contains no elements.
- size(): Returns the number of elements in the deque.
- clear(): Removes all elements from the deque.
Implementation Classes:
The Deque
interface has several implementation classes in Java:
- ArrayDeque: Resizable-array implementation of the
Deque
interface. - LinkedList: Doubly linked list implementation of the
Deque
interface.