I am not able to understand , how swap function is working could you please make it clear
Array Demo Swap
@adi8.sahu,
In the swap function we pass arr, i, j. We swap index i and j. Now in the swap method we pass reference of the array and swap index i and j. As soon as it returns back to the main method, the changes are made in the original array.
Example:
Array a: 1 2 3 4 5
Swap (a,0,2)
Now before entering swap function a will be: 1 2 3 4 5
After swap function a will be : 3 2 1 4 5
The changes will be made in the current array.