Mental Model
A stack works like a pile where the last item added is the first to be removed. We can use a queue, which normally removes the first item added, to act like a stack by rearranging items after each addition.
Analogy: Imagine a line of people (queue) where normally the first person in line is served first. To act like a stack, after a new person joins at the end, they move to the front by everyone else stepping back, so the newest person is served first.
Queue before push: front -> [1, 2, 3] ← rear After push(4) and rearranging: front -> [4, 1, 2, 3] ← rear
