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/d2/d52/heap__sort_8cpp_source.html below:

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

Go to the documentation of this file. 38 for

(

int

i = 0; i < sz; i++) std::cout << arr[i] <<

" "

;

58void

heapify(T *arr,

int

n,

int

i) {

63 if

(l < n && arr[l] > arr[largest])

66 if

(r < n && arr[r] > arr[largest])

70

std::swap(arr[i], arr[largest]);

71

heapify(arr, n, largest);

85 for

(

int

i = n - 1; i >= 0; i--) heapify(arr, n, i);

87 for

(

int

i = n - 1; i >= 0; i--) {

88

std::swap(arr[0], arr[i]);

100

std::cout <<

"Test 1\n"

;

101 int

arr[] = {-10, 78, -1, -6, 7, 4, 94, 5, 99, 0};

102 int

sz =

sizeof

(arr) /

sizeof

(arr[0]);

106

assert(std::is_sorted(arr, arr + sz));

107

std::cout <<

"Test 1 Passed\n========================\n"

;

109

std::cout <<

"Test 2\n"

;

110 double

arr2[] = {4.5, -3.6, 7.6, 0, 12.9};

111

sz =

sizeof

(arr2) /

sizeof

(arr2[0]);

115

assert(std::is_sorted(arr2, arr2 + sz));

116

std::cout <<

"Test 2 passed\n"

;

double l(double x)

Another test function.

void heapSort(T *arr, int n)

void printArray(T *arr, int sz)


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