Example. I’ve got an array with 15 objects. I want to start enumerating from a given index. Say start at index 5 and then the index above, the index under, above, under etc… I don’t want it to wrap around, but rather stop and continue in unexplored direction.
So the order of indexes in my example would be.
5, 6, 4, 7, 3, 8, 2, 9, 1, 10, 0, 11, 12, 13, 14
How can this be done?
Here’s a more compact implementation that doesn’t require creating subarrays: