fix: fixed index of parent in sorting/heap_sort_2.c (#914)

* fixed index of parent

* fixed spacing to pass autochecks

* Empty commit to test the CI

Co-authored-by: Panquesito7 <halfpacho@gmail.com>
This commit is contained in:
Dhruv Pasricha 2022-01-12 00:02:09 +05:30 committed by GitHub
parent d8804a60ab
commit f851fbbe2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,10 +81,10 @@ void heapifyDown(int8_t *arr, const uint8_t size)
*/ */
void heapifyUp(int8_t *arr, uint8_t i) void heapifyUp(int8_t *arr, uint8_t i)
{ {
while (i > 0 && arr[i / 2] < arr[i]) while (i > 0 && arr[(i - 1) / 2] < arr[i])
{ {
swap(&arr[i / 2], &arr[i]); swap(&arr[(i - 1) / 2], &arr[i]);
i /= 2; i = (i - 1) / 2;
} }
} }