#include <iostream>
#include<stack>
using namespace std;
struct Queue {
stack<int> s1, s2;
void enQueue(int x)
{
while (!s1.empty()) {
s2.push(s1.top());
s1.pop();
}
s1.push(x);
while (!s2.empty()) {
s1.push(s2.top());
s2.pop();
}
}
int deQueue()
{
if (s1.empty()) {
cout << "Q is Empty";
exit(0);
}
int x = s1.top();
s1.pop();
return x;
}
};
int main()
{
Queue q;
q.enQueue(1);
q.enQueue(2);
q.enQueue(3);
cout << q.deQueue() << '\n';
cout << q.deQueue() << '\n';
cout << q.deQueue() << '\n';
return 0;
}
Comments
Leave a comment