Queue Made of Two Stacks
hardQuestion 525Build a class StackQueue that behaves like a first-in first-out queue of ints but is implemented with two stack<int> members only (no queue, deque or vector).
Implement these public methods:
1. void enqueue(int x) — adds x to the back of the queue
2. int dequeue() — removes and returns the element at the front of the queue; if the queue is empty, return -1
3. int size() const — returns the total number of elements as an int
Example: after enqueue(1) and enqueue(2) the test calls dequeue() three times and prints each result on its own line (see Expected Output).
Do NOT write a main function.
Expected output
1 2 -1 5 2 6 7 0 -1
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
STL ContainersStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.