Input : N = 7, pos = 6, arr = {1, 2, 3, 4, 9, 15, 0}
Output: 0 1 2 3 4 9 15
Explanation:
Applying following swap arr can be sorted:
1. swap element 0 and 1, Now arr is {0, 2, 3, 4, 9, 15, 1}
2. swap element 1 and 2, Now arr is {0, 1, 3, 4, 9, 15, 2}
3. swap element 2 and 3, Now arr is {0, 1, 2, 4, 9, 15, 3}
4. swap element 3 and 4, Now arr is {0, 1, 2, 3, 9, 15, 4}
5. swap element 4 and 9, Now arr is {0, 1, 2, 3, 4, 15, 9}
6. swap element 9 and 15, Now arr is {0, 1, 2, 3, 4, 9, 15}
We can see now, the array arr[ ] has been sorted.
Input: N = 4, pos = 2, arr = {2, 3, 1, 4, }
Output: 1 2 3 4
Below is the implementation of the above approach.