(int[] arr)
| 8 | |
| 9 | } |
| 10 | static void cycleSort(int[] arr) |
| 11 | { |
| 12 | int i = 0; |
| 13 | while (i < arr.length) |
| 14 | { |
| 15 | int correct= arr[i]-1; |
| 16 | if(arr[i]!=arr[correct]) |
| 17 | swap(arr,i,correct); |
| 18 | else |
| 19 | i++; |
| 20 | } |
| 21 | |
| 22 | } |
| 23 | static void swap(int[] arr,int a, int b) |
| 24 | { |
| 25 | int temp; |