![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Strand Sort algorithm. More...
#include <iostream>#include <list>Go to the source code of this file.
Namespaces | |
| namespace | sorting |
| for working with vectors | |
| namespace | strand |
| Functions for Strand Sort algorithm. | |
Functions | |
| template<typename T> | |
| std::list< T > | sorting::strand::strand_sort (std::list< T > lst) |
| Apply sorting. | |
| static void | test () |
| Function for testing. | |
| int | main () |
| Main function. | |
Implementation of Strand Sort algorithm.
Strand Sort is a sorting algorithm that works in \(O(n)\) time if list is already sorted and works in \(O(n^2)\) in worst case.
It is passed over the array to be sorted once and the ascending (sequential) numbers are taken. After the first iteration, the sequential sub-array is put on the empty sorted array. The main sequence is passed over again and a new sub-sequence is created in order. Now that the sorted array is not empty, the newly extracted substring is merged with the sorted array. Repeat types 3 and 4 until the sub-sequence and main sequence are empty.
Definition in file strand_sort.cpp.
| int main | ( | void | ) |
Main function.
Definition at line 84 of file strand_sort.cpp.
| std::list< T > sorting::strand::strand_sort | ( | std::list< T > | lst | ) |
Apply sorting.
| element | type of list |
| lst | List to be sorted |
Definition at line 36 of file strand_sort.cpp.
|
static |
Function for testing.
Definition at line 64 of file strand_sort.cpp.