可怜的界面排版工人,刚摆完界面,感觉好枯燥,写一点Rust调剂一下哦, 我就是喜欢贴在博客里,方便我以后看。
fn max(arg: &[int]) -> int {
let mut x = arg[0];
for val in arg.iter() {
if *val > x {x = *val}
}
x
}
fn main() {
let x = [1, 2, 3, 4, 5, 2, 4, 5, 8, 10, 0];
let max2 = |arg: &[int]| -> int {
let mut x = arg[0];
for val in arg.iter() {
if *val > x {x = *val}
}
x
};
let mut num = max(x);
println!("num = {}", num);
num = max2(x);
println!("num = {}", num);
}