diff --git a/lab3/zad3/plots/comp.pdf b/lab3/zad3/plots/comp.pdf index 2330ac3..a784926 100644 Binary files a/lab3/zad3/plots/comp.pdf and b/lab3/zad3/plots/comp.pdf differ diff --git a/lab3/zad3/plots/comp_n.pdf b/lab3/zad3/plots/comp_n.pdf index 22192f7..c744ead 100644 Binary files a/lab3/zad3/plots/comp_n.pdf and b/lab3/zad3/plots/comp_n.pdf differ diff --git a/lab3/zad3/plots/swap.pdf b/lab3/zad3/plots/swap.pdf index 699c75b..8b32c89 100644 Binary files a/lab3/zad3/plots/swap.pdf and b/lab3/zad3/plots/swap.pdf differ diff --git a/lab3/zad3/plots/swap_n.pdf b/lab3/zad3/plots/swap_n.pdf index 926a1db..680cb0b 100644 Binary files a/lab3/zad3/plots/swap_n.pdf and b/lab3/zad3/plots/swap_n.pdf differ diff --git a/lab3/zad3/plots/time.pdf b/lab3/zad3/plots/time.pdf index cee889a..f25e9b2 100644 Binary files a/lab3/zad3/plots/time.pdf and b/lab3/zad3/plots/time.pdf differ diff --git a/lab3/zad3/plots/time_n.pdf b/lab3/zad3/plots/time_n.pdf index 91d16fa..cb190e2 100644 Binary files a/lab3/zad3/plots/time_n.pdf and b/lab3/zad3/plots/time_n.pdf differ diff --git a/libselect/src/normal_select.rs b/libselect/src/normal_select.rs index 3389cfd..428ffe3 100644 --- a/libselect/src/normal_select.rs +++ b/libselect/src/normal_select.rs @@ -28,7 +28,7 @@ impl NormalSelect { pub fn partition(&mut self, list: &mut Vec, lo: usize, hi: usize, pivot: u64) -> usize { use CompareResult::*; - let mut pivot_index = 0; + let mut pivot_index = lo; for i in lo..=hi { if self.compare(pivot, list[i]) == EQUAL { @@ -73,12 +73,12 @@ impl NormalSelect { if self.should_print { println!("list: {:?}; lo: {lo}; hi: {hi}; ord_stat: {ord_stat}; k: {k}", list); } let n = hi - lo + 1; - let num_groups = if n % 5 == 0 { n / 5 } else { (n / 5) + 1 }; + let num_groups = if n % k == 0 { n / k } else { (n / k) + 1 }; let mut medians: Vec = vec![0; num_groups]; let mut index = 0; - for i in (lo..=hi).step_by(5) { - if i + 4 <= hi { - self.insertion_sort(list, i, i + 4); + for i in (lo..=hi).step_by(k) { + if i + (k - 1) <= hi { + self.insertion_sort(list, i, i + (k - 1)); medians[index] = list[i + 2]; index += 1; } else { @@ -94,18 +94,18 @@ impl NormalSelect { println!("pivot_index: {pivot_index}; pivot: {pivot}"); } let r = self.partition(list, lo, hi, pivot); - let k = r - lo + 1; + let i = r - lo + 1; if self.should_print { println!("r: {r}"); - println!("k: {k}"); + println!("i: {i}"); } - if k == ord_stat { + if i == ord_stat { if self.should_print { println!("k == ord_stat"); } return (r, list[r]); - } else if k < ord_stat { + } else if i < ord_stat { if self.should_print { println!("k < ord_stat"); } - return self._select(list, r + 1, hi, ord_stat - k, k); + return self._select(list, r + 1, hi, ord_stat - i, k); } else { if self.should_print { println!("k > ord_stat"); } return self._select(list, lo, r - 1, ord_stat, k);