rust中数组不能动态创建,所以只能利用Vectors.
Vec自带的有sort函数。
记录一下代码是因为Vec提供了get(索引),insert(索引,值)等方法,但是没有提供修改指定索引处值得方法。
所以利用好Vec跟数组一样的索引访问方式就好了。
fn t2(s:&str){
let mut vs = Vec::from(s);
let mut out_index = 0;
while out_index<vs.len()-1 {
let mut index = 0;
while index<vs.len()-out_index-1 {
let c1 = vs.get(index).unwrap().clone();
let c2 = vs.get(index+1).unwrap().clone();
if c1>c2{
let tem = c1;
vs[index]=c2;
vs[index+1]=tem;
}
index = index +1;
}
out_index = out_index+1;
}
let s = String::from_utf8_lossy(vs.as_slice());
println!("{}",s)
}
0 0