fix dual pivot quicksort error

This commit is contained in:
jacekpoz 2024-04-10 12:47:08 +02:00
parent 2b3c7f70d4
commit 95fc5a1e1d
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -27,9 +27,6 @@ fn swap(list: &mut [u64], i: usize, j: usize, swaps: &mut u64) {
use CompareResult::*;
fn dual_pivot_partition(list: &mut [u64], res: &mut SortResult) -> (usize, usize) {
if list.len() < 2 {
return (0, 0);
}
let mut comps = 0;
let mut swaps = 0;
@ -76,7 +73,7 @@ fn dual_pivot_partition(list: &mut [u64], res: &mut SortResult) -> (usize, usize
fn dual_pivot_quick_sort(list: &mut [u64], print: bool) -> SortResult {
let mut res = SortResult::default();
if list.len() == 0 {
if list.len() <= 1 {
return res;
}
@ -87,7 +84,7 @@ fn dual_pivot_quick_sort(list: &mut [u64], print: bool) -> SortResult {
print_list(&list);
}
let res1 = dual_pivot_quick_sort(&mut list[0..=(lp - 1)], print);
let res1 = if lp == 0 { res.clone() } else { dual_pivot_quick_sort(&mut list[0..=(lp - 1)], print) };
let res2 = dual_pivot_quick_sort(&mut list[(lp + 1)..=(rp - 1)], print);
let res3 = dual_pivot_quick_sort(&mut list[(rp + 1)..], print);