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/d3/d92/pancake__sort_8cpp_source.html below:

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

Go to the documentation of this file. 43void reverse

(std::vector<T> &arr,

int

start,

int

end) {

45 while

(start <= end) {

47

arr[start] = arr[end];

62 for

(

int

i = size; i > 1; --i) {

63 int

max_index = 0, j = 0;

65 for

(j = 0; j < i; j++) {

66 if

(arr[j] >= max_value) {

71 if

(max_index != i - 1)

89

std::cout <<

"\nTest 1- as std::vector<int>..."

;

90

std::vector<int> arr1 = {23, 10, 20, 11, 12, 6, 7};

92

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

93

std::cout <<

"Passed\n"

;

94 for

(

int

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

95

std::cout << arr1[i] <<

" ,"

;

97

std::cout << std::endl;

101

std::cout <<

"\nTest 2- as std::vector<double>..."

;

102

std::vector<double> arr2 = {23.56, 10.62, 200.78, 111.484,

103

3.9, 1.2, 61.77, 79.6};

105

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

106

std::cout <<

"Passed\n"

;

107 for

(

int

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

108

std::cout << arr2[i] <<

", "

;

110

std::cout << std::endl;

114

std::cout <<

"\nTest 3- as std::vector<float>..."

;

115

std::vector<float> arr3 = {6.56, 12.62, 200.78, 768.484, 19.27, 68.87, 9.6};

117

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

118

std::cout <<

"Passed\n"

;

119 for

(

int

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

120

std::cout << arr3[i] <<

", "

;

122

std::cout << std::endl;

Functions for Pancake sort algorithm.

void reverse(std::vector< T > &arr, int start, int end)

This implementation is for reversing elements in a a C-style array .

static void test()

Test implementations.

int pancakeSort(std::vector< T > &arr, int size)

This implementation is for a C-style array input that gets modified in place.

int main()

Main function.


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