-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackUsingQueue.cpp
More file actions
55 lines (47 loc) · 878 Bytes
/
stackUsingQueue.cpp
File metadata and controls
55 lines (47 loc) · 878 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class MyStack
{
public:
queue<int> q1, q2;
MyStack()
{
}
void push(int x)
{
// int y;
q1.push(x);
if (!q2.empty())
{
while (q2.empty() != true)
{
q1.push(q2.front());
q2.pop();
}
while (q1.empty() != true)
{
q2.push(q1.front());
q1.pop();
}
}
else
{
q2.push(x);
q1.pop();
}
}
int pop()
{
int y = q2.front();
q2.pop();
return y;
}
int top()
{
return q2.front();
}
bool empty()
{
// if(q2.empty()==true){
// }
return q2.empty() == true ? true : false;
}
};