Guest User

Untitled

a guest
Jun 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. extern crate typed_arena;
  2. use typed_arena::Arena;
  3.  
  4. #[derive(Debug, Clone)]
  5. struct Node {
  6. v: i64,
  7. l: Option<&Node>,
  8. r: Option<&Node>,
  9. }
  10.  
  11. fn ins(arena: &Arena<Node>, t: Option<&Node>, v: i64) -> Option<&Node> {
  12. match t {
  13. None =>
  14. Some(arena.alloc(&Node{v: v, l: None, r: None})),
  15. Some(n) =>
  16. if v < n.v {
  17. Some(arena.alloc(&Node{v: n.v, l: ins(n.l, v), r: n.r}))
  18. } else {
  19. Some(arena.alloc(&Node{v: n.v, l: n.l, r: ins(n.r, v)}))
  20. }
  21. }
  22. }
  23.  
  24. fn main() {
  25. let mut arena = Arena::new();
  26. let t = arena.alloc(Node{v: 5, l: None, r: None});
  27. let t2 = ins(arena, Some(&t), 3);
  28. println!("Hello World! {:?}", t2);
  29. }
Add Comment
Please, Sign In to add comment