-
Notifications
You must be signed in to change notification settings - Fork 0
/
P84.java
42 lines (32 loc) · 824 Bytes
/
P84.java
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
import java.util.*;
public class P84 {
static class Stack {
Queue<Integer> q = new LinkedList<>();
public Stack() {
}
/*----------------- Public Functions of Stack -----------------*/
public int getSize() {
return q.size();
}
public boolean isEmpty() {
return q.isEmpty();
}
public void push(int element) {
int size = q.size();
q.offer(element);
while (size-- != 0) {
q.offer(q.poll());
}
}
public int pop() {
if (q.isEmpty())
return -1;
return q.poll();
}
public int top() {
if (q.isEmpty())
return -1;
return q.peek();
}
}
}