add correctness check

This commit is contained in:
jacekpoz 2024-05-08 22:03:16 +02:00
parent 8c3d30f6f6
commit 66f5b09849
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 6 additions and 2 deletions

View file

@ -47,7 +47,8 @@ fn main() -> io::Result<()> {
println!("start state: {:?}", input_list); println!("start state: {:?}", input_list);
println!("end state: {:?}", list); println!("end state: {:?}", list);
let mut insertion = InsertionSort::new(false); let mut insertion = InsertionSort::new(false);
println!("sorted array: {:?}", insertion.sort(&input_list)); let sorted = insertion.sort(&input_list);
println!("sorted array: {:?}", sorted);
let ordinal_indicator = match order_statistic { let ordinal_indicator = match order_statistic {
1 => "st", 1 => "st",
2 => "nd", 2 => "nd",
@ -55,6 +56,7 @@ fn main() -> io::Result<()> {
_ => "th", _ => "th",
}; };
println!("{}{} order statistic: {}", order_statistic, ordinal_indicator, result); println!("{}{} order statistic: {}", order_statistic, ordinal_indicator, result);
println!("is correct: {}", result == sorted[order_statistic - 1]);
} }
println!("swaps: {}", randomized.num_swap()); println!("swaps: {}", randomized.num_swap());

View file

@ -47,7 +47,8 @@ fn main() -> io::Result<()> {
println!("start state: {:?}", input_list); println!("start state: {:?}", input_list);
println!("end state: {:?}", list); println!("end state: {:?}", list);
let mut insertion = InsertionSort::new(false); let mut insertion = InsertionSort::new(false);
println!("sorted array: {:?}", insertion.sort(&input_list)); let sorted = insertion.sort(&input_list);
println!("sorted array: {:?}", sorted);
let ordinal_indicator = match order_statistic { let ordinal_indicator = match order_statistic {
1 => "st", 1 => "st",
2 => "nd", 2 => "nd",
@ -55,6 +56,7 @@ fn main() -> io::Result<()> {
_ => "th", _ => "th",
}; };
println!("{}{} order statistic: {}", order_statistic, ordinal_indicator, result); println!("{}{} order statistic: {}", order_statistic, ordinal_indicator, result);
println!("is correct: {}", result == sorted[order_statistic - 1]);
} }
println!("swaps: {}", normal.num_swap()); println!("swaps: {}", normal.num_swap());