diff --git a/Sorts/cyclesort.java b/Sorts/cyclesort.java new file mode 100644 index 00000000..5b7e5652 --- /dev/null +++ b/Sorts/cyclesort.java @@ -0,0 +1,78 @@ +import java.util.*; +import java.lang.*; + +class Sorting +{ + // Function that sort the array using Cycle sort + public static void cycleSort (int arr[], int n) + { + // count number of memory writes + int writes = 0; + + // traverse array elements + for (int cycle_start=0; cycle_start<=n-2; cycle_start++) + { + // initialize item as starting point + int item = arr[cycle_start]; + + // Find position where we put the item. + int pos = cycle_start; + for (int i = cycle_start+1; i