![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Bogosort algorithm More...
#include <iostream>#include <algorithm>#include <array>#include <cassert>#include <random>Go to the source code of this file.
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.
Definition in file bogo_sort.cpp.
| int main | ( | void | ) |
Driver Code
Definition at line 107 of file bogo_sort.cpp.
| void show_array | ( | const std::array< T, N > & | arr | ) |
Function to display array on screen
| T | typename of the array |
| N | length of array |
| arr | array to display |
Definition at line 71 of file bogo_sort.cpp.
| void test | ( | ) |
Function to test above algorithm
Definition at line 81 of file bogo_sort.cpp.