Skip to content

Commit d2b4cdf

Browse files
committed
feat: Double-Ended Queue
Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 43202ca commit d2b4cdf

File tree

1 file changed

+24
-24
lines changed
  • Section 25 Collections Frameworks/Queue Interface/Deque/src

1 file changed

+24
-24
lines changed
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
Overview
21
The Deque<E> interface (short for Double-Ended Queue, pronounced "deck") extends Queue<E> and SequencedCollection<E>.
2+
33
It represents a linear collection that allows insertion and removal of elements from both ends.
44

55
Most implementations of Deque do not impose a fixed size limit, but capacity-restricted deques can be implemented as well.
66

7-
Operations
8-
This interface provides methods for insertion, removal, and examination of elements at both ends of the deque. Each operation comes in two forms:
7+
Operations:
8+
9+
This interface provides methods for insertion, removal, and examination of elements at both ends of the deque.
910

11+
Each operation comes in two forms:
1012
Throws an exception if the operation fails.
1113
Returns a special value (null or false) if the operation fails.
1214

13-
### **Deque<E> (java.util)**
15+
Deque<E> (java.util)
1416

15-
#### **Overview**
16-
The `Deque<E>` interface (short for **Double-Ended Queue**, pronounced "deck") extends `Queue<E>` and `SequencedCollection<E>`. It represents a **linear collection** that allows **insertion and removal of elements from both ends**.
17+
Overview:
18+
The `Deque<E>` interface (short for **Double-Ended Queue**, pronounced "deck") extends `Queue<E>` and
19+
`SequencedCollection<E>`.
1720

18-
Most implementations of `Deque` **do not impose a fixed size limit**, but capacity-restricted deques can be implemented as well.
21+
It represents a linear collection that allows **insertion and removal of elements from both ends.
1922

20-
---
23+
Most implementations of `Deque` do not impose a fixed size limit, but capacity-restricted deques can be implemented
24+
as well.
2125

22-
##### Summary of Deque Methods
26+
27+
Summary of Deque Methods:
2328

2429
| Operation | First Element (Head) | Last Element (Tail) |
2530
|--------------|----------------------------------------|--------------------------------------|
@@ -30,18 +35,17 @@ Most implementations of `Deque` **do not impose a fixed size limit**, but capaci
3035
| Examine | getFirst() (Throws exception) | getLast() (Throws exception) |
3136
| | peekFirst() (Returns special value) | peekLast() (Returns special value) |
3237

33-
---
3438

35-
#### FIFO Behavior (Queue Mode)
39+
FIFO Behavior (Queue Mode)
3640

3741
When used as a queue, Deque follows FIFO (First-In-First-Out) behavior:
3842

3943
- Elements are added at the end (offerLast(e)).
4044
- Elements are removed from the front (pollFirst()).
4145

42-
##### Comparison of Queue and Deque Methods
46+
Comparison of Queue and Deque Methods
4347

44-
| Queue Method** | **Equivalent Deque Method** |
48+
| Queue Method | Equivalent Deque Method |
4549
|----------------|-----------------------------|
4650
| add(e) | addLast(e) |
4751
| offer(e) | offerLast(e) |
@@ -52,9 +56,9 @@ When used as a queue, Deque follows FIFO (First-In-First-Out) behavior:
5256

5357
---
5458

55-
#### LIFO Behavior (Stack Mode)
59+
LIFO Behavior (Stack Mode)
5660

57-
A Deque can also function as a LIFO (Last-In-First-Out) stack**, serving as a modern replacement for the legacy Stack class.
61+
A Deque can also function as a LIFO (Last-In-First-Out) stack, serving as a modern replacement for the legacy Stack class.
5862
- Elements are pushed to the front (addFirst(e)).
5963
- Elements are popped from the front (removeFirst()).
6064

@@ -73,25 +77,21 @@ A Deque can also function as a LIFO (Last-In-First-Out) stack**, serving as a mo
7377
# Additional Functionalities
7478

7579
- Removing Interior Elements:
76-
7780
- removeFirstOccurrence(Object o): Removes the first occurrence of a specified element.
7881
- removeLastOccurrence(Object o): Removes the last occurrence of a specified element.
79-
8082
- No Indexed Access: Unlike List<E>, Deque<E> does not support indexed element access.
8183

8284
- Null Elements:
83-
- Deque implementations are **not strictly required** to prohibit null elements.
84-
- However, using null is discouraged because it conflicts with methods that return null to indicate an empty deque**.
85+
- Deque implementations are not strictly required** to prohibit null elements.
86+
- However, using null is discouraged because it conflicts with methods that return null to indicate an empty deque.
8587

8688
- Equality & Hashing:
87-
8889
- Deque implementations do not override** equals() and hashCode().
8990
- Instead, they inherit identity-based implementations from Object.
9091

9192
---
9293

93-
#Additional Information:
94-
94+
# Additional Information:
9595
- Part of the Java Collections Framework
9696
- Introduced in Java 1.6
9797
- Designed by Doug Lea & Josh Bloch
@@ -100,7 +100,7 @@ A Deque can also function as a LIFO (Last-In-First-Out) stack**, serving as a mo
100100
---
101101

102102
Conclusion:
103+
The Deque<E> interface is a versatile data structure that can function as both a queue (FIFO) and a stack (LIFO).
103104

104-
The Deque<E> interface is a versatile data structure that can function as both **a queue (FIFO) and a stack (LIFO).
105105
It provides efficient insertion and removal operations at both ends,
106-
making it well-suited for double-ended processing scenarios.
106+
making it well-suited for double-ended processing scenarios.

0 commit comments

Comments
 (0)