I'm just playing around with rust for the first time, implementing quicksort, and I'm stuck on references to dynamically sized arrays (I had no problem with fixed size arrays).
I would like to have an indefinitely sized array of integers to sort, which I gather I can create with something like:
let array = ~[1,2,3,4,3,2,1];
However, I am not sure how I can pass this by reference into a partition function.
partition ( a : &mut ~[uint], p: uint, i: uint) {
// partition a, in place
}
As soon as I try to reorder any elements in a, the compiler complains:
error: cannot assign to immutable vec content
a[..]
&mut ~[...]says that the vector (and its data) thatapoints at is mutable. At a guess, you've written something likea = ...at some point?