From f851fbbe2f3bd018fd26a4307634a42e816884ec Mon Sep 17 00:00:00 2001 From: Dhruv Pasricha <78498002+DhruvPasricha@users.noreply.github.com> Date: Wed, 12 Jan 2022 00:02:09 +0530 Subject: [PATCH] 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 --- sorting/heap_sort_2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sorting/heap_sort_2.c b/sorting/heap_sort_2.c index b93205e1..1cce1ec6 100644 --- a/sorting/heap_sort_2.c +++ b/sorting/heap_sort_2.c @@ -81,10 +81,10 @@ void heapifyDown(int8_t *arr, const uint8_t size) */ 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]); - i /= 2; + swap(&arr[(i - 1) / 2], &arr[i]); + i = (i - 1) / 2; } }