Skip to content

Commit

Permalink
Update smooth_sort.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkgits committed Oct 7, 2024
1 parent 78fbc3e commit 24fad3d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/sorting/smooth_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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);
Expand Down

0 comments on commit 24fad3d

Please sign in to comment.