Skip to content

Commit f2505b6

Browse files
committed
feat: add ArrayDequeDemo demonstrating double-ended queue operations in Java
Implemented ArrayDequeDemo.java to illustrate how ArrayDeque supports both queue (FIFO) and stack (LIFO) behaviors. Demonstrates insertion using offerFirst(), offerLast() and removal with pollFirst(), pollLast(), highlighting its O(1) performance and flexibility as a non-thread-safe, resizable array-based deque. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 9c70287 commit f2505b6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Section 25 Collections Frameworks/Queue Interface/Deque/Array Deque/src/ArrayDequeDemo.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class ArrayDequeDemo {
44
public static void main(String[] args) {
55
ArrayDeque<Integer> DQ = new ArrayDeque<>();
66
/*
7-
new ArrayDeque<>(); Constructor.
7+
new ArrayDeque<>(); // Constructor.
88
Takes Constant time.
99
*/
1010

@@ -13,14 +13,14 @@ public static void main(String[] args) {
1313
DQ.offerLast(40);
1414
DQ.offerLast(30);
1515

16-
//DQ.pollFirst(); //Inserting from last and deleting from first.Acting like a Queue.
17-
//DQ.pollLast(); //Stack delete and insert from last.
16+
// DQ.pollFirst(); // Inserting from last and deleting from first.Acting like a Queue.
17+
// DQ.pollLast(); // Stack delete and insert from last.
1818

19-
/* DQ.offerFirst(1);
19+
/*
20+
DQ.offerFirst(1);
2021
DQ.offerFirst(2);
2122
DQ.offerFirst(3);
22-
*/
23-
24-
DQ.forEach((x)-> System.out.println(x));
23+
*/
24+
DQ.forEach((x)-> System.out.println(x));
2525
}
26-
}
26+
}

0 commit comments

Comments
 (0)