A random thought. There is an easy way to implement a FIFO queue with a pair of ...
Slava Pestov @slava@mathstodon.xyz
A random thought. There is an easy way to implement a FIFO queue with a pair of growable stacks: you enqueue elements by pushing them on the first stack, and you dequeue by popping from the second stack, but if the second stack is empty, you reverse the first stack and swap the two stacks.
It also looks like this generalizes to a double ended queue, where now you can pop from either stack, and if it’s empty you reverse the other one and swap. But this seems to suffer from a performance pathology where now you can get in a state where you’re “bouncing” the same set of elements back and forth between the two stacks. Is there an easy way to fix that?