我是 Rust 编程新手。我想用递归实现合并排序。这是我的代码:
fn merge(a: &mut Vec<u32>, b: &mut Vec<u32>) -> Vec<u32> {
let mut temp: Vec<u32> = Vec::new();
println!("The digit is {}", a[0]);
while a.len() > 0 && b.len() > 0 {
if a[0] > b[0] {
temp.push(a[0]);
a.pop();
} else {
temp.push(b[0]);
b.pop();
}
}
while a.len() > 0 {
temp.push(a[0]);
a.pop();
}
while b.len() > 0 {
temp.push(b[0]);
b.pop();
}
temp
}
fn merge_sort(v: &mut Vec<u32>) -> Vec<u32> {
println!("The divided vector is: {:?}", v);
let n …Run Code Online (Sandbox Code Playgroud)