| 1 | import java.util.Arrays; |
| 2 | public class CycleSort { |
| 3 | public static void main(String[] args) { |
| 4 | |
| 5 | int[] arr= {5,4,3,2,1}; |
| 6 | cycleSort(arr); |
| 7 | System.out.println(Arrays.toString(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; |
| 26 | temp=arr[a]; |
| 27 | arr[a]=arr[b]; |
| 28 | arr[b]=temp; |
| 29 | } |
| 30 | } |
nothing calls this directly
no outgoing calls
no test coverage detected