-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack using queue
49 lines (37 loc) · 988 Bytes
/
Stack using queue
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
import java.util.* ;
import java.io.*;
public class Stack {
// Define the data members.
private Deque<Integer>queue1;
public Stack() {
// Implement the Constructor.
queue1=new ArrayDeque<Integer>();
}
/*----------------- Public Functions of Stack -----------------*/
public int getSize() {
// Implement the getSize() function.
return queue1.size();
}
public boolean isEmpty() {
// Implement the isEmpty() function.
if(queue1.isEmpty())
return true;
return false;
}
public void push(int element) {
// Implement the push(element) function.
queue1.push(element);
}
public int pop() {
// Implement the pop() function.
if(isEmpty())
return -1;
return queue1.poll();
}
public int top() {
// Implement the top() function.
if(isEmpty())
return -1;
return queue1.getFirst();
}
}