How many stacks are required to implement a queue if no other data structures such as arrays or linked lists are available?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This is a very interesting problem. Here is what you do.
Take two stacks, call one stack the loading stack and the other unloading.
To enqueue:
To dequeue: