I have an NSMutableArray
holding NSStrings
e.g. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
I would like to be able to shift elements with wrapping.
So e.g. move 1 to the centre, shifting all elements, wrapping the remaining ones (that cross the bounds) to the start again, and vice versa e.g. 10 to the centre.
{7, 8, 9, 10, 1, 2, 3, 4, 5, 6}
and {6, 7, 8, 9, 10, 1, 2, 3, 4, 5}
Is there an optimised sort
method like this already existing?
for
loop, one for the firstk
elements say 1-6 and next for remainingm
elements i.e 7-10. andk+m = n
which is size of the array. But i am not aware of any standard algorithm as such. – Praveen S yesterdaytrueIndex = (offset + index) % array.count
. I think that's better than linear time. – Hot Licks yesterday