| 15 | queue<int> q2; |
| 16 | |
| 17 | void enque(int x) |
| 18 | { |
| 19 | // Push x first in empty q2 |
| 20 | q2.push(x); |
| 21 | |
| 22 | // Push all the remaining elements in q1 to q2. |
| 23 | while(!q1.empty()) |
| 24 | { |
| 25 | q2.push(q1.front()); |
| 26 | q1.pop(); |
| 27 | } |
| 28 | // Swap the names of two queues |
| 29 | queue<int> temp = q1; |
| 30 | q1 = q2; |
| 31 | q2 = temp; |
| 32 | } |
| 33 | |
| 34 | int dequeue() |
| 35 | { |