| 9 | // 3. Push everything back to stack1. |
| 10 | |
| 11 | struct Queue |
| 12 | { |
| 13 | stack<int> s1; |
| 14 | stack<int> s2; |
| 15 | |
| 16 | // oldest entered element is always at the top of stack 1 |
| 17 | void enque(int x) |
| 18 | { |
| 19 | s1.push(x); |
| 20 | } |
| 21 | |
| 22 | // deQueue operation just pops from stack1 |
| 23 | int dequeue() |
| 24 | { |
| 25 | if(s1.empty()) |
| 26 | return 0; |
| 27 | else |
| 28 | { |
| 29 | while(!s1.empty()) |
| 30 | { |
| 31 | s2.push(s1.top()); |
| 32 | s1.pop(); |
| 33 | } |
| 34 | } |
| 35 | int x = s2.top(); |
| 36 | s2.pop(); |
| 37 | return x; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | int main() |
| 42 | { |
nothing calls this directly
no outgoing calls
no test coverage detected