-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackusingqueues.cpp
More file actions
96 lines (73 loc) · 1 KB
/
Copy pathstackusingqueues.cpp
File metadata and controls
96 lines (73 loc) · 1 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
#include<queue>
using namespace std;
queue<int> s1;
queue<int> s2;
void psh(int n){
s1.push(n);
}
void transfr1(){
if(!s1.empty()){
int t=s1.front();
s1.pop();
transfr1();
s2.push(t);
}
else{
return ;
}
}
void transfr2(){
if(!s2.empty()){
int t=s2.front();
s2.pop();
//s3.push(t);
transfr2();
transfr1();
s2.push(t);
//s3.pop();
}
else{
return;
}
}
int pop1(){
if(s1.empty()&& s2.empty()){
return -9999;// Both queue empty meaning underflow;
}
if(!s1.empty()){
if(s2.empty()){
transfr1();}
else{
transfr2();
}
}
int t=s2.front();
s2.pop();
return t;
}
int main(){
psh(1);
psh(2);
cout<<pop1()<<endl;
cout<<pop1()<<endl;
psh(3);
psh(4);
psh(5);
cout<<pop1()<<endl;
cout<<pop1()<<endl;
psh(6);
psh(7);
psh(8);
cout<<pop1()<<endl;
cout<<pop1()<<endl;
psh(61);
psh(72);
psh(83);
cout<<pop1()<<endl;
cout<<pop1()<<endl;
cout<<pop1()<<endl;
cout<<pop1()<<endl;
cout<<pop1()<<endl;
cout<<pop1()<<endl;
}