A first pass at using rust, an implementation of select sort algorithm…
fn main() {
let mut xs : [i32; 6] = [50,20,70,10,60,30];
let arr_len = xs.len();
for o in 1..arr_len {
let mut sm_ind = o;
for i in o..arr_len {
if xs[i].lt(&xs[sm_ind]) {
sm_ind = i;
}
}
xs.swap(o, sm_ind);
}
for n in 1..arr_len {
print!("{} ", xs[n]);
}
println!();
}
A few things learned in this excercise:
-
Need to use mut ahead of variable declaration as default is for immutable declaration.
-
Type check used at compile time, as a lot of errors were a result of mismatched types.
-
Feels like I just translated an implementation done in C, thus would be interested in seeing what a veteran rustecean implementation would look like.