apply cargo warning suggested fixes

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-02-10 16:15:51 -08:00
parent 83571aaf88
commit 3e96f815b1
9 changed files with 32 additions and 82 deletions

View File

@@ -1,27 +1,3 @@
pub fn binary_search<T: Ord>(a: &[T], item: &T) -> usize {
let mut low = 0;
let mut high = a.len();
while low < high {
let mid = low + (high - low) / 2;
if item <= &a[mid] {
high = mid;
} else {
low = mid + 1;
}
}
low
}
pub fn binary_insertion_sort<T: Ord>(vec: &mut Vec<T>) {
for i in 1..vec.len() {
let val = vec.remove(i);
let pos = binary_search(&vec[0..i], &val);
vec.insert(pos, val);
}
}
pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &Vec<T>, vec2: &Vec<T>) -> Vec<T> {
let mut merged = Vec::with_capacity(vec1.len() + vec2.len());
let mut i = 0;