0% found this document useful (0 votes)
37 views10 pages

Deque

A deque (double-ended queue) is a queue that allows additions and removals at both ends. There are two types: input restricted deque which allows insertions at one end and deletions at both, and output restricted deque which allows deletions at one end and insertions at both. Deques can be implemented using LinkedList or ArrayDeque in Java. Common methods include add, addFirst, addLast, removeFirst, and removeLast. Common applications include undo-redo operations.

Uploaded by

Apurba Mondal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views10 pages

Deque

A deque (double-ended queue) is a queue that allows additions and removals at both ends. There are two types: input restricted deque which allows insertions at one end and deletions at both, and output restricted deque which allows deletions at one end and insertions at both. Deques can be implemented using LinkedList or ArrayDeque in Java. Common methods include add, addFirst, addLast, removeFirst, and removeLast. Common applications include undo-redo operations.

Uploaded by

Apurba Mondal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

DEQUE

PRESENTED BY
Apurba Mondal
What is deque?
● Deque or double-ended queues are redefined queues in
which elements can be added or removed at either end
but not in the middle.
Types of Deque
There are two types of deque:
● Input Restricted Deque-is a deque which allows

insertions at only one end but allows deletions at both


ends of the list.

● Output Restricted Deque-is a deque which allows


deletions at only one end of the list but allows insertions
at both ends of the list.
Deque implementation:
Since Java deque is an interface, we need to implement in order to use it.
We can use either of the following deque implementations in the Java
collections API-

java.util.LinkedList();
or
java.util.ArrayDeque();
Creating a Deque:
Before we can use a Java Deque, we must create an instance
of one of the classes that implements the deque interface.

This is an example of creating a Java Deque by creating a LinkedList


deque-

Deque deque = new LinkedList();


Methods implemented in Deque:
● These are some of the methods implemented in Deque-
● add(element): Adds an element to the tail.
● addFirst(element): Adds an element to the head.
● addLast(element): Adds an element to the tail.
● offer(element): Adds an element to the tail and returns a boolean to
explain if the insertion was successful.
● offerFirst(element): Adds an element to the head and returns a
boolean to explain if the insertion was successful.
● offerLast(element): Adds an element to the tail and returns a boolean
to explain if the insertion was successful.
● push(element): Adds an element to the head.
● pop(element): Removes an element from the head and returns it.
● removeFirst(): Removes the element at the head.
● removeLast(): Removes the element at the tail.
Java Program to demonstrate Deque:
Applications of Deque:
● A common application of the deque is to use it for
undo-redo operations in a software application.

You might also like