Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Implementation of gnome sort algorithm. More...
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
Namespaces | |
namespace | sorting |
for working with vectors | |
Functions | |
template<typename T > | |
void | sorting::gnomeSort (T *arr, int size) |
template<typename T , size_t size> | |
std::array< T, size > | sorting::gnomeSort (std::array< T, size > arr) |
static void | test () |
int | main () |
Implementation of gnome sort algorithm.
Gnome sort algorithm is not the best one but it is widely used. The algorithm iteratively checks the order of pairs in the array. If they are on right order it moves to the next successive pair, otherwise it swaps elements. This operation is repeated until no more swaps are made thus indicating the values to be in ascending order.
The time Complexity of the algorithm is \(O(n^2)\) and in some cases it can be \(O(n)\).
int main | ( | void | ) |
|
static |
Test function