complete threads till 06

This commit is contained in:
2025-04-15 16:25:01 +05:30
parent 9bc063a05b
commit 4fbee2d894
9 changed files with 67 additions and 19 deletions

View File

@@ -15,7 +15,14 @@
use std::thread;
pub fn sum(v: Vec<i32>) -> i32 {
todo!()
// let mut c1 = (v.clone()[..v.len() / 2]).iter().collect::<Vec<_>>();
// let mut c2 = (v.clone()[v.len() / 2..]).iter().collect::<Vec<_>>();
let (c1, c2) = v.split_at(v.len() / 2);
let c1 = c1.to_vec();
let c2 = c2.to_vec();
let t1 = std::thread::spawn(move || c1.iter().sum::<i32>());
let t2 = std::thread::spawn(move || c2.iter().sum::<i32>());
t1.join().unwrap() + t2.join().unwrap()
}
#[cfg(test)]