TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Cycle sort algorithm. More...
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
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. | |
static void | test () |
Test implementations. | |
int | main () |
Main function. | |
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.
Definition in file cycle_sort.cpp.
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 |
Definition at line 38 of file cycle_sort.cpp.
int main | ( | void | ) |
Main function.
Definition at line 128 of file cycle_sort.cpp.
|
static |
Test implementations.
Definition at line 92 of file cycle_sort.cpp.