mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Bug Fix heap sort [Fresh Implementation]
This commit is contained in:
commit
803981c831
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user