-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDequeueArray.java
More file actions
58 lines (54 loc) · 1.31 KB
/
DequeueArray.java
File metadata and controls
58 lines (54 loc) · 1.31 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package Framework;
import java.util.ArrayDeque;
class queue{
ArrayDeque<Integer> MyQueue = new ArrayDeque<>();
void insert(int n){
MyQueue.offerLast(n);
}
void delete(){
MyQueue.pollFirst();
}
int show(){
return MyQueue.peekFirst();
}
}
class stack{
ArrayDeque<Integer> MyStack = new ArrayDeque<>();
void insert(int n){
MyStack.offerFirst(n);
}
void delete(){
MyStack.pollFirst();
}
int show(){
return MyStack.peekFirst();
}
}
public class DequeArray {
public static void main(String[] args) {
ArrayDeque<Integer> AD1 = new ArrayDeque<>();
System.out.println(AD1);
AD1.add(99);
AD1.offer(100);
AD1.offerFirst(101);
AD1.offerLast(102);
//System.out.println(AD1);
AD1.forEach((x)->System.out.print(x+" "));
System.out.println();
AD1.poll();
AD1.forEach((x)->System.out.print(x+" "));
System.out.println();
queue QE = new queue();
QE.insert(73);
QE.insert(51);
QE.insert(23);
QE.delete();
System.out.println(QE.show());
stack SE = new stack();
SE.insert(10);
SE.insert(11);
SE.insert(12);
SE.delete();
System.out.println(SE.show());
}
}