Reverse order of elements of an array

Reverse order of elements of an Array


Iterative way

Initialize start and end indexes

start = 0, end = n1

In a loop, swap arr [start] with arr [end] and change start and end as follows.

start = start + 1, end = end – 1.

Recursion way

Initialize start and end indexes

start = 0, end = n1.

Swap arr [start] with arr[end].

Recursively call reverse for rest of the array.

For example if a is an array of integers with three elements such that

a [0] = 1

a [1] = 2

a [2] = 3

Then on reversing the array will be

a [0] = 3

a [1] = 2

a [0] = 1