Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate typed_arena;
- use typed_arena::Arena;
- #[derive(Debug, Clone)]
- struct Node {
- v: i64,
- l: Option<&Node>,
- r: Option<&Node>,
- }
- fn ins(arena: &Arena<Node>, t: Option<&Node>, v: i64) -> Option<&Node> {
- match t {
- None =>
- Some(arena.alloc(&Node{v: v, l: None, r: None})),
- Some(n) =>
- if v < n.v {
- Some(arena.alloc(&Node{v: n.v, l: ins(n.l, v), r: n.r}))
- } else {
- Some(arena.alloc(&Node{v: n.v, l: n.l, r: ins(n.r, v)}))
- }
- }
- }
- fn main() {
- let mut arena = Arena::new();
- let t = arena.alloc(Node{v: 5, l: None, r: None});
- let t2 = ins(arena, Some(&t), 3);
- println!("Hello World! {:?}", t2);
- }
Add Comment
Please, Sign In to add comment