-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathstackUsingQueue.cpp
More file actions
50 lines (43 loc) · 792 Bytes
/
stackUsingQueue.cpp
File metadata and controls
50 lines (43 loc) · 792 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
#include<bits/stdc++.h>
using namespace std;
class Stack{
queue<int>q;
public:
void push(int x){
int s=q.size();
q.push(x);
for(int i=0; i<s; i++){
q.push(q.front());
q.pop();
}
}
void pop(){
q.pop();
}
int Top(){
return q.front();
}
int Size()
{
return q.size();
}
void print()
{
while(!q.empty()){
cout<<q.front()<<endl;
q.pop();
}
}
};
int main()
{
Stack st;
st.push(3);
st.push(2);
st.push(4);
st.push(1);
// st.pop();
cout<<st.Top()<<endl;
st.print();
return 0;
}