-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyDeque.java
More file actions
41 lines (28 loc) · 716 Bytes
/
MyDeque.java
File metadata and controls
41 lines (28 loc) · 716 Bytes
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
import java.util.Deque;
import java.util.LinkedList;
public class MyDeque {
static class StackUsingDeque {
Deque<Integer> d = new LinkedList<>();
public void push(int data) {
d.addFirst(data);
}
public int pop() {
return d.removeFirst();
}
public int peek() {
return d.peekFirst();
}
}
static class QueueUsingDeque {
Deque<Integer> d = new LinkedList<>();
public void add(int data) {
d.addLast(data);
}
public int remove() {
return d.removeFirst();
}
public int peek() {
return d.peekFirst();
}
}
}