• + 1 comment

    This code is still perfectly functional, but a little expensive: you'll need to transfer all elements in the 'queue' twice for every enqueue. (Enqueueing 10 and then dequeue 10 would result in ~90 elements transferred worst case.)

    Using the method I suggest, you'll only need to transfer all elements in the 'queue' once, and only in the special situation (of not having a 'refreshed' old stack). So enqueueing 10 and dequeue 10 would result in ~10 elements transferred worst case.)