in reply to Re^4: Incrementing string arrays when used with foreach loops
in thread Incrementing string arrays when used with foreach loops

I associate the top of the deck with the start of the deck, and thus the start of the array. And I usually see push/shift used for queues, not unshift/pop. There's nothing stopping you from using the latter, but you have to start using negative offsets to index and splice the array.

  • Comment on Re^5: Incrementing string arrays when used with foreach loops

Replies are listed 'Best First'.
Re^6: Incrementing string arrays when used with foreach loops
by tilly (Archbishop) on Sep 16, 2008 at 06:30 UTC
    Last I checked, push was substantially faster than unshift, which is a pretty good argument for using push/shift rather than unshift/pop.

    The first time I checked, the difference was O(1) vs O(n). I fixed that to O(1) for both, but with a significantly worse constant on unshift.