Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions stack/stackUsingQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
Binary file added stack/stackUsingQueue.exe
Binary file not shown.