Re:What's wrong with this code, really?
by seabee on Friday September 16, 2011 @02:00PM
(#3005531)
If you don't re-address each element, how do you map the value at index 1 to index 0?
One way is to leave the indexes intact and keep an offset around, so you may map the nth logical index to the nth physical one. (Add 1 on a shift, subtract 1 on an unshift.)
One way is to leave the indexes intact and keep an offset around, so you may map the nth logical index to the nth physical one. (Add 1 on a shift, subtract 1 on an unshift.)
But if you wanted this behaviour, there are more efficient ways: http://en.wikipedia.org/wiki/Circular_buffer