Bug Fix heap sort [Fresh Implementation]

This commit is contained in:
Ayaan Khan 2020-06-21 00:07:40 +05:30
commit 803981c831

View File

@ -34,8 +34,7 @@
*
*/
auto printArray = [](int *arr, int sz) {
for (int i = 0 ; i < sz ; i++)
std::cout << arr[i] <<" ";
for (int i = 0; i < sz; i++) std::cout << arr[i] << " ";
std::cout << "\n";
};
@ -72,8 +71,7 @@ void(*heapify)(int *arr, int n, int i) = [] (int *arr, int n, int i) {
*
*/
auto heapSort = [](int *arr, int n) {
for (int i = n-1 ; i >= 0; i--)
heapify(arr, n, i);
for (int i = n - 1; i >= 0; i--) heapify(arr, n, i);
for (int i = n - 1; i >= 0; i--) {
std::swap(arr[0], arr[i]);