|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Implementation of Cycle sort algorithm. More...
#include <algorithm>#include <cassert>#include <iostream>#include <vector>Namespaces | |
| namespace | sorting |
| for working with vectors | |
| namespace | cycle_sort |
| Functions for Cycle sort algorithm. | |
Functions | |
| template<typename T > | |
| std::vector< T > | sorting::cycle_sort::cycleSort (const std::vector< T > &in_arr) |
| The main function implements cycleSort. More... | |
| static void | test () |
| Test implementations. More... | |
| int | main () |
| Main function. More... | |
Implementation of Cycle sort algorithm.
Cycle Sort is a sorting algorithm that works in \(O(n^2)\) time in the best case and works in \(O(n^2)\) in worst case. If a element is already at its correct position, do nothing. If a element is not at its correct position, we then need to move it to its correct position by computing the correct positions.Therefore, we should make sure the duplicate elements.
| std::vector< T > sorting::cycle_sort::cycleSort | ( | const std::vector< T > & | in_arr | ) |
The main function implements cycleSort.
| T | type of array |
| in_arr | array to be sorted |
| int main | ( | void | ) |
|
static |
Test implementations.