From 24fad3dc0911a9bec5215239331387451290e3e3 Mon Sep 17 00:00:00 2001 From: kanishkgits Date: Mon, 7 Oct 2024 21:19:44 +0530 Subject: [PATCH] Update smooth_sort.rs --- src/sorting/smooth_sort.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sorting/smooth_sort.rs b/src/sorting/smooth_sort.rs index d8c48f6480a..d898d8407e2 100644 --- a/src/sorting/smooth_sort.rs +++ b/src/sorting/smooth_sort.rs @@ -49,7 +49,7 @@ fn remove_from_leonardo_heap( } } -fn heapify_leonardo(nums: &mut [i32], index: usize, sizes: &[usize], heaps: usize) { +fn heapify_leonardo(nums: &mut [i32], index: usize, sizes: &[usize], mut heaps: usize) { let mut current = index; let mut heap_size = sizes[heaps]; @@ -58,8 +58,12 @@ fn heapify_leonardo(nums: &mut [i32], index: usize, sizes: &[usize], heaps: usiz break; } - let left_child = current.checked_sub(heap_size).expect("Underflow error: heap_size is too large"); - let right_child = current.checked_sub(1).expect("Underflow error: current is too small"); + let left_child = current + .checked_sub(heap_size) + .expect("Underflow error: heap_size is too large"); + let right_child = current + .checked_sub(1) + .expect("Underflow error: current is too small"); if nums[current] < nums[left_child] { nums.swap(current, left_child);