Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one implement a queue with only a stack implementation?

Tags:

queue

I know with 2 stacks.but how with one?

like image 669
taashu Avatar asked Dec 07 '25 08:12

taashu


1 Answers

You can "cheat" by using recursive function calls to pop the stack, then you push the item being queued, then as the recursive calls unwind you push what was popped. But this is really two stacks, because the system program counter is a stack.

like image 63
Ross Presser Avatar answered Dec 09 '25 16:12

Ross Presser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!