|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Implementation of Bogosort algorithm More...
#include <iostream>#include <algorithm>#include <array>#include <cassert>Namespaces | |
| namespace | sorting |
| for working with vectors | |
Functions | |
| template<typename T , size_t N> | |
| std::array< T, N > | sorting::shuffle (std::array< T, N > arr) |
| template<typename T , size_t N> | |
| std::array< T, N > | sorting::randomized_bogosort (std::array< T, N > arr) |
| template<typename T , size_t N> | |
| void | show_array (const std::array< T, N > &arr) |
| void | test () |
| int | main () |
Implementation of Bogosort algorithm
In computer science, bogosort (also known as permutation sort, stupid sort, slowsort, shotgun sort, random sort, monkey sort, bobosort or shuffle sort) is a highly inefficient sorting algorithm based on the generate and test paradigm. Two versions of this algorithm exist: a deterministic version that enumerates all permutations until it hits a sorted one, and a randomized version that randomly permutes its input.Randomized version is implemented here.
Shuffle the array untill array is sorted.
| int main | ( | void | ) |
Driver Code
| void show_array | ( | const std::array< T, N > & | arr | ) |
| void test | ( | ) |
Function to test above algorithm