TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of gnome sort algorithm. More...
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
Go to the source code of this file.
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)\).
Definition in file gnome_sort.cpp.
int main | ( | void | ) |
Our main function with example of sort method.
Definition at line 130 of file gnome_sort.cpp.
|
static |
Test function
Definition at line 85 of file gnome_sort.cpp.