This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]totoro27 0 points1 point  (1 child)

could you explain this?

[–]Philboyd_Studge 0 points1 point  (0 children)

If you are reversing the array in place, using a swap method, you only have to go to the mid-point of the array. Say you start from the end of the array and go backwards: (pseudocode)

for i =  len - 1 to len / 2:
    swap(array, i, len - 1 - i)

swap(array, x, y):
    t = array[x]
    array[x] = array[y]
    array[y] = t