Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,42 @@
|
|||
struct TreeNode<T> {
|
||||
value: T,
|
||||
left: Option<Box<TreeNode<T>>>,
|
||||
right: Option<Box<TreeNode<T>>>,
|
||||
}
|
||||
|
||||
impl <T> TreeNode<T> {
|
||||
fn my_map<U>(&self, f: |t: &T| -> U) -> TreeNode<U> {
|
||||
TreeNode{value: f(&self.value),
|
||||
left:
|
||||
match self.left {
|
||||
None => None,
|
||||
Some(ref n) => Some(box() n.my_map(|n| f(n))),
|
||||
},
|
||||
right:
|
||||
match self.right {
|
||||
None => None,
|
||||
Some(ref n) => Some(box() n.my_map(|n| f(n))),
|
||||
},}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let root =
|
||||
TreeNode{value: 3i,
|
||||
left:
|
||||
Some(box() TreeNode{value: 55i,
|
||||
left: None,
|
||||
right: None,}),
|
||||
right:
|
||||
Some(box() TreeNode{value: 234i,
|
||||
left:
|
||||
Some(box() TreeNode{value: 0i,
|
||||
left: None,
|
||||
right:
|
||||
None,}),
|
||||
right: None,}),};
|
||||
root.my_map(|x| { println!("{}" , x)});
|
||||
println!("---------------");
|
||||
let new_root = root.my_map(|x| *x as f64 * 333.333f64);
|
||||
new_root.my_map(|x| { println!("{}" , x) });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue