formatting source-code for e464ddac36

This commit is contained in:
github-actions 2020-06-20 18:34:51 +00:00
parent e464ddac36
commit 97bf410b36

View File

@ -33,9 +33,8 @@
* @param sz size of array * @param sz size of array
* *
*/ */
auto printArray = [] (int *arr, int sz) { auto printArray = [](int *arr, int sz) {
for (int i = 0 ; i < sz ; i++) for (int i = 0; i < sz; i++) std::cout << arr[i] << " ";
std::cout << arr[i] <<" ";
std::cout << "\n"; std::cout << "\n";
}; };
@ -48,10 +47,10 @@ auto printArray = [] (int *arr, int sz) {
* @param arr array be to sorted * @param arr array be to sorted
* @param * @param
*/ */
void(*heapify)(int *arr, int n, int i) = [] (int *arr, int n, int i) { void (*heapify)(int *arr, int n, int i) = [](int *arr, int n, int i) {
int largest = i; int largest = i;
int l = 2*i + 1; int l = 2 * i + 1;
int r = 2*i + 2; int r = 2 * i + 2;
if (l < n && arr[l] > arr[largest]) if (l < n && arr[l] > arr[largest])
largest = l; largest = l;
@ -73,11 +72,10 @@ void(*heapify)(int *arr, int n, int i) = [] (int *arr, int n, int i) {
* @param n size of array * @param n size of array
* *
*/ */
auto heapSort = [] (int *arr, int n) { auto heapSort = [](int *arr, int n) {
for (int i = n-1 ; i >= 0; i--) for (int i = n - 1; i >= 0; i--) heapify(arr, n, i);
heapify(arr, n, i);
for (int i = n-1 ; i >= 0; i--) { for (int i = n - 1; i >= 0; i--) {
std::swap(arr[0], arr[i]); std::swap(arr[0], arr[i]);
heapify(arr, i, 0); heapify(arr, i, 0);
} }