Zadanko
unknown
rust
5 years ago
1.1 kB
9
Indexable
fn main() {
let a:Vec<i64> = vec![1,2,8];
let b:Vec<i64> = vec![0,5,7];
let c:Vec<i64> = merge(a, b);
println!("{:?}", c)
}
fn merge(a:Vec<i64>, b:Vec<i64>) -> Vec<i64> {
let mut ai = a.iter();
let mut bi = b.iter();
let mut result:Vec<i64> = vec![];
loop{
if let (Some(ak), None) = (ai.next(), bi.next());
if let ()
match (ai.last(), bi.last()){
(Some(ak), None) => {result.push(*ak); ai.next();},
(None, Some(bk)) => {result.push(*bk); bi.next();},
(Some(ak), Some(bk)) => if ak > bk {result.push(*ak); ai.next();} else {result.push(*bk); bi.next();},
(None, None) => return result,
}
}
/*loop{
match (ai.last(), bi.last()){
(Some(ak), None) => {result.push(*ak); ai.next();},
(None, Some(bk)) => {result.push(*bk); bi.next();},
(Some(ak), Some(bk)) => if ak > bk {result.push(*ak); ai.next();} else {result.push(*bk); bi.next();},
(None, None) => return result,
}
}*/
}
Editor is loading...