← Back to STL Containers
Question 525
Queue Made of Two Stacks
Queue Made of Two Stacks
Build a classStackQueuethat behaves like a first-in first-out queue of ints but is implemented with twostack<int>members only (noqueue,dequeorvector). Implement these public methods: 1.void enqueue(int x)— addsxto 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 anintExample: afterenqueue(1)andenqueue(2)the test callsdequeue()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 — 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.