Here is the files that I have
main.rs
mod sort;
fn main() {
let v = ~[0,1,3,7,5,7,9,4,2,6,9,5,3,5,0,7,6,9,0,2,3,4,2,4,7,9,7];
sort::mergeSort(v);
sort::print(v);
}
and
sort.rs
use std::vec;
pub fn mergeSort<T: Clone+Ord>(a: &mut[T]){
let mid = a.len()/2 as uint;
let mut aux = vec::with_capacity(mid+1);
__mergesort(a, 0, a.len(), aux);
fn __mergesort<T: Clone+Ord>(a: &mut[T], lo: uint, hi: uint, aux: &mut[T]){
let mid = a.len()/2 as uint;
if mid > 0 {
__mergesort(a, lo, mid, aux);
__mergesort(a, mid+1, hi, aux);
__merge(a, mid, aux);
}
fn __merge<T: Clone+Ord>(a: &mut[T], lo: uint, mid: uint, hi: uint, aux: &mut[T]) {
__clone_array(a, 0, mid+1, aux, 0);
let mut i = 0;
let mut j = 0;
let mut k = 0;
while k < a.len() {
if j >= a.len()-mid {
__clone_array(a, k, a.len(), aux, 0);
break;
} else if i >= mid {
break;
}
if aux[i] <= a[mid+j] {
a[k] = aux[i];
i += 1;
} else {
a[k] = a[mid+j];
j += 1;
}
k += 1;
}
}
fn __clone_array<T: Clone>(a: &[T], af: uint, al: uint, b: &mut[T], bf: uint){
for i in range(bf, bf+al-af) {
b[i] = a[af+i].clone();
}
}
}
}
pub fn print<T: ToStr>(v: &[T]) {
print!("[ ");
for i in range(0, v.len()) {
print!("{} ", v[i].to_str());
}
println!("]");
}
Here is the error that I get
sort.rs:44:23: 44:41 error: unresolved name vec::with_capacity.
sort.rs:44 let mut aux = vec::with_capacity(mid+1); ^~~~~~~~~~~~~~~~~~
error: aborting due to previous error
What am I doing wrong?
rustc -v.)__? It’s entirely superfluous.