Deque

A deque (pronounced "deck") is a double-ended queue, hence its name. A deque is like a queue, except that elements can also be inserted at the head of the queue, not just at the end. This also makes it possible to use it like a stack.

The deque is new as of Java 6, and Sun/Oracle recommends to use the deque for all queue and stack implementations, and the queue and stack from Java 5 have become deprecated. The deque also contains the stack, as elements can be inserted at the head of the queue, and it provides the familiar stack functions for popping and pushing as well.

The deque is used internally in the JavaTools function JMooreBellmann[], which is an implementation of the D'Esopo Pape variant of the Moore-Bellmann algorithm to solve the minimum cost path problem from a source node to all other nodes, permitting negative arc lenghts in a network without negative cycles. The D'Esopo Pape variant is the fastest method for the Moore-Bellmann algorithm known today, and it depends on a deque for the node labelling.

In JavaTools the functions for the deque are the same as for the queue (see there), with the following additions:

same as JDequePoll[]

same as JDequePeek[]

same as JDequeOffer[]

same as JDequeAdd[]

same as JDequeGet[]

can be used to model a stack.

can be used to model a stack.

same as JDequeRemove[]

removes the element of the first occurrence of a specified element

removes the element of the last occurrence of a specified element