We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9a93c3a commit c9e871cCopy full SHA for c9e871c
Queues/Implementation/usingStack.cpp
@@ -0,0 +1,39 @@
1
+#include <bits/stdc++.h>
2
+using namespace std;
3
+
4
+int main() {
5
6
7
+// queue implementation using two stacks
8
+stack<int> st1;
9
+stack<int> st2;
10
11
+int i=0;
12
+ while(i<5){
13
+ //algo
14
+ // 1. Push everything from stack1 to stack2
15
+ // 2. insert x or num to stack 1
16
+ // 3. Again push every number from stack2 to stack1
17
+ int x;
18
+ cin>>x;
19
+ while(!st1.empty()){
20
+ st2.push(st1.top());
21
+ st1.pop();
22
+ }
23
+ st1.push(x);
24
25
+ while(!st2.empty()){
26
+ st1.push(st2.top());
27
+ st2.pop();
28
29
+ i++;
30
31
32
33
+ cout<<st1.top()<<" ";
34
35
36
37
38
39
+}
0 commit comments