Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sorting/bogo_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <random>


/**
Expand Down Expand Up @@ -50,8 +51,10 @@ std::array <T, N> shuffle (std::array <T, N> arr) {
template <typename T, size_t N>
std::array <T, N> randomized_bogosort (std::array <T, N> arr) {
// Untill array is not sorted
std::random_device random_device;
std::mt19937 generator(random_device());
while (!std::is_sorted(arr.begin(), arr.end())) {
std::random_shuffle(arr.begin(), arr.end());// Shuffle the array
std::shuffle(arr.begin(), arr.end(), generator);// Shuffle the array
}
return arr;
}
Expand Down
Loading