CJCoding With Joseph
15free / daySign inCreate account

Transfer One Stack Into the Other

StackQueue fakes a queue out of two stacks: enqueue pushes onto inbox, while dequeue and peek take from outbox, which holds values already flipped into arrival order. Both call transfer() first, and only transfer() is missing.

Requirements:
1. Do nothing at all while outbox still holds values.
2. Only when outbox is empty, pop every value off inbox and push it onto outbox.

Do NOT write a main method.

Expected Output:

1
2
3
4
-1

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Data Structures & AlgorithmsQueues
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.