From cbe6df6e708d12fc950ab00c3db71e9217219540 Mon Sep 17 00:00:00 2001 From: SUBHAM KUMAR PANDEY Date: Mon, 6 Sep 2021 00:51:47 +0530 Subject: [PATCH] chore(CPlusPlus): add cycle-sort (#440) --- algorithms/CPlusPlus/README.md | 1 + algorithms/CPlusPlus/Sorting/cycle-sort.cpp | 127 ++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 algorithms/CPlusPlus/Sorting/cycle-sort.cpp diff --git a/algorithms/CPlusPlus/README.md b/algorithms/CPlusPlus/README.md index 9fae1305..3d85290a 100644 --- a/algorithms/CPlusPlus/README.md +++ b/algorithms/CPlusPlus/README.md @@ -81,6 +81,7 @@ 12. [Binary Insertion Sort](Sorting/binary-insertion-sort.cpp) 13. [Merge Sort](Sorting/merge-sort.cpp) 14. [Wave Sort](Sorting/wave-sort.cpp) +15. [Cycle Sort](Sorting/cycle-sort.cpp) ## Strings diff --git a/algorithms/CPlusPlus/Sorting/cycle-sort.cpp b/algorithms/CPlusPlus/Sorting/cycle-sort.cpp new file mode 100644 index 00000000..00f3bb07 --- /dev/null +++ b/algorithms/CPlusPlus/Sorting/cycle-sort.cpp @@ -0,0 +1,127 @@ +// ***Cycle Sort*** +// This sorting algorithm is best suited for situations where memory write or swap operations are costly. +// it is In-place and not stable + +#include +using namespace std; + +void cycleSort(int arr[], int size) +{ + for(int cyclestart=0;cyclestart