Java stack vs deque

broken image
broken image

This is similar to iterating other linear data structures like list, array, etc.

broken image

Deque in Java is an extension of the Queue interface. Hence it can be used as a Stack (Last-In-First-Out) or a Queue (First-In-First-Out). Deque stands for double-ended queue because it allows retrieval, addition, and removal from both ends.

broken image

Deque Interfaceĭeque in Java is an interface, and it belongs to the java.util package. This is one of the real-time examples of deque where we allow people to join and leave from both ends of the queue. This is a special case where we allow people to join the queue from the front. In some scenarios, a person who just left the queue can have some clarifications and may need to join the queue directly from the front. IntroductionĬonsider a real-world scenario where people are standing in a queue in a bank. Deque is an acronym for double-ended queue. It can be used both as a queue (FIFO policy) and as a stack (LIFO policy). It supports a linear data structure that allows insertion and deletion of elements at both ends. Deque in Java is a subtype of the Queue interface in java.util package.

broken image