-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassroomDeque.java
More file actions
58 lines (46 loc) · 1.28 KB
/
Copy pathClassroomDeque.java
File metadata and controls
58 lines (46 loc) · 1.28 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
import java.util.*;
import java.util.LinkedList;
public class ClassroomDeque {
static class Stack {
Deque<Integer> deque = new LinkedList<>();
public void push(int data) {
deque.addLast(data);
}
public int pop() {
return deque.removeLast();
}
public int peek() {
return deque.getLast();
}
}
static class Queue {
Deque<Integer> deque = new LinkedList<>();
public void add(int data) {
deque.addLast(data);
}
public int remove() {
return deque.removeFirst();
}
public int peek() {
return deque.getFirst();
}
}
public static void main(String args[]) {
// Stack s = new Stack();
// s.push(1);
// s.push(2);
// s.push(3);
// System.out.println("Peek = " + s.peek());
// System.out.println(s.pop());
// System.out.println(s.pop());
// System.out.println(s.pop());
Queue q=new Queue();
q.add(1);
q.add(2);
q.add(3);
System.out.println("Peek = " + q.peek());
System.out.println(q.remove());
System.out.println(q.remove());
System.out.println(q.remove());
}
}