A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d5/ddb/bogo__sort_8cpp_source.html below:

TheAlgorithms/C++: sorting/bogo_sort.cpp Source File

Go to the documentation of this file. 36template

<

typename

T,

size_t

N>

37

std::array <T, N>

shuffle

(std::array <T, N> arr) {

38 for

(

int

i = 0; i < N; i++) {

40

std::swap(arr[i], arr[std::rand() % N]);

51template

<

typename

T,

size_t

N>

54

std::random_device random_device;

55

std::mt19937 generator(random_device());

56 while

(!std::is_sorted(arr.begin(), arr.end())) {

57

std::shuffle(arr.begin(), arr.end(), generator);

70template

<

typename

T,

size_t

N>

73

std::cout << x <<

' '

;

83

std::array <int, 5> arr1;

84 for

(

int

&x : arr1) {

85

x = std::rand() % 100;

87

std::cout <<

"Original Array : "

;

90

std::cout <<

"Sorted Array : "

;

92

assert(std::is_sorted(arr1.begin(), arr1.end()));

94

std::array <int, 5> arr2;

95 for

(

int

&x : arr2) {

96

x = std::rand() % 100;

98

std::cout <<

"Original Array : "

;

101

std::cout <<

"Sorted Array : "

;

103

assert(std::is_sorted(arr2.begin(), arr2.end()));

111

std::array <int, 5> arr = {3, 7, 10, 4, 1};

112

std::cout <<

"Original Array : "

;

115

std::cout <<

"Sorted Array : "

;

void show_array(const std::array< T, N > &arr)

std::array< T, N > shuffle(std::array< T, N > arr)

std::array< T, N > randomized_bogosort(std::array< T, N > arr)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4