You are viewing a single comment's thread. Return to all comments →
Imagine the second stack is just the front of the queue.
one = 123, two = []
2
one = [], two = 23
1 6789
one = 6789, two = 23, queue = 236789
one = 6789, two = 3, queue = 36789
one = [] two = 6789, queue = 6789
It'll pop from two until two is empty, then repopulate two from one.
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
Imagine the second stack is just the front of the queue.
one = 123, two = []
2
one = [], two = 23
1 6789
one = 6789, two = 23, queue = 236789
2
one = 6789, two = 3, queue = 36789
2
one = [] two = 6789, queue = 6789
It'll pop from two until two is empty, then repopulate two from one.