1 class MyQueue {
2 public:
3 stack<int> stack1;
4 stack<int> stack2;
5
6 MyQueue() {
7 // do intialization if necessary
8 }
9
10 void push(int element) {
11 // write your code here
12 stack1.push(element);
13 }
14
15 int pop() {
16 // write your code here
17 int data;
18 if(stack2.empty()) {
19 while(!stack1.empty()) {
20 data = stack1.top();
21 stack2.push(data);
22 stack1.pop();
23 }
24 }
25
26 data = stack2.top();
27 stack2.pop();
28 return data;
29 }
30
31 int top() {
32 // write your code here
33 int data;
34 if(stack2.empty()) {
35 while(!stack1.empty()) {
36 data = stack1.top();
37 stack2.push(data);
38 stack1.pop();
39 }
40 }
41 else
42 data = stack2.top();
43 return data;
44 }
45 };