-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackQ.java
More file actions
47 lines (43 loc) · 1.1 KB
/
StackQ.java
File metadata and controls
47 lines (43 loc) · 1.1 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
import java.util.ArrayDeque;
import java.util.Deque;
class StackQ {
void forstack(){
Deque<Integer> s = new ArrayDeque<Integer>();
// for stack
s.push(1);
s.push(2);
System.out.println(s);
System.out.println(s.peek());
s.pop();
System.out.println(s.peek());
}
void forqueue(){
Deque<Integer> s = new ArrayDeque<Integer>();
s.offer(1);
s.offer(2);
System.out.println(s);
System.out.println(s.peek());
s.poll();
System.out.println(s.peek());
}
void forgeneral() {
Deque<Integer> s = new ArrayDeque<Integer>();
s.add(1);
s.add(2);
s.add(3);
System.out.println(s);
s.remove();
System.out.println(s);
s.removeLast();
System.out.println(s);
}
public static void main(String[] args) {
StackQ a = new StackQ();
System.out.println("stack:");
a.forstack();
System.out.println("queue:");
a.forqueue();
System.out.println("general:");
a.forgeneral();
}
}