diff --git a/src/sorting/smooth_sort.rs b/src/sorting/smooth_sort.rs index a3346c3443d..a367a74c93c 100644 --- a/src/sorting/smooth_sort.rs +++ b/src/sorting/smooth_sort.rs @@ -57,8 +57,8 @@ fn heapify_leonardo(nums: &mut [i32], index: usize, sizes: &[usize], mut heaps: break; } - let left_child = current.saturating_sub(heap_size); - let right_child = current.saturating_sub(1); + let left_child = if current >= heap_size { current - heap_size } else { break }; + let right_child = if current > 0 { current - 1 } else { break }; if nums[current] < nums[left_child] { nums.swap(current, left_child); @@ -71,7 +71,7 @@ fn heapify_leonardo(nums: &mut [i32], index: usize, sizes: &[usize], mut heaps: } heaps -= 1; - heap_size = heap_size.saturating_sub(1); + heap_size = sizes[heaps]; } }