From 7f9e288c309e08240dc0227d7c135434e766f0fb Mon Sep 17 00:00:00 2001 From: honey8899 Date: Sun, 22 Oct 2023 01:17:38 +0530 Subject: [PATCH] added cycle sort in c --- DSA_Codesheet/C/cycle_sort.c | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 DSA_Codesheet/C/cycle_sort.c diff --git a/DSA_Codesheet/C/cycle_sort.c b/DSA_Codesheet/C/cycle_sort.c new file mode 100644 index 0000000..196b13a --- /dev/null +++ b/DSA_Codesheet/C/cycle_sort.c @@ -0,0 +1,77 @@ +#include +void cycleSort (int arr[], int n) +{ + // count number of memory writes + int writes = 0; + + // traverse array elements and put it to on the right place + + for (int i=0; i<=n-2; i++) + { + int item = arr[i]; + + int pos = i; + for (int j = i+1; j