-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDequeue.java
More file actions
39 lines (33 loc) · 1.78 KB
/
ArrayDequeue.java
File metadata and controls
39 lines (33 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//* Implement the Array Dequeue and methods
//! ArrayDequeue is an Interface.
//! ArrayDeque = Resizable array + Deque interface.
//! There are no capacity restrictions for ArrayDeque, and it provides us the facility to add or remove any element from both sides of the queue.
//TODO: Also known as Double Ended queue
public class ArrayDequeue {
public static void main(String[] args) {
java.util.ArrayDeque<Integer> ad1 = new java.util.ArrayDeque<>();
// ? Insert the elements in the Array Dequeue
// This will insert the elements in the sequentially manner (one after other)
ad1.add(1);
ad1.add(2);
ad1.add(3);
ad1.add(4);
ad1.add(5);
// ? Print the elements of the ArrayDequeue
System.out.println(ad1.getFirst()); // This will print the first elements of th Array
System.out.println(ad1.getLast()); // This will print the last elements of the Array
// ? Insert the elements in the Array
ad1.addFirst(11); // This will add the elements at the first of the array
ad1.addLast(55); // This will add the elements at the last of the array
// ? Access the first and last elements of the array
System.out.println(ad1.peekFirst()); // This will give the first elements of the array
System.out.println(ad1.peekLast()); // This will give the last elements of the array
// ? Convert the String Representation of the array
System.out.println(ad1.toString()); // This will convert the Array into String array
// ? Print the elements of the ArrayDequeue using like this
System.out.println("Printing elements of the ArrayDequeue : ");
for (int i = 0; i <= ad1.size() - 1; i++) {
System.out.print(ad1.toArray()[i] + ", ");
}
}
}