Closed lvyuemeng closed 5 months ago
fn it_works() {
let mut arr1 = [2, 3, 4, 5];
assert_eq!(quick_select(&mut arr1, 0, 3, 1), 3);
let mut arr2 = [2, 5, 9, 12, 16];
assert_eq!(quick_select(&mut arr2, 1, 3, 2), 12);
let mut arr2 = [0, 3, 8];
assert_eq!(quick_select(&mut arr2, 0, 0, 0), 0);
}
in the second instance of the test, the right answer should be 9, not 12.
In the partition function:
in the range of (left..right+1),the list.swap(right,store_index) should be placed out of the iteration. here the pesudo code in wiki: