Advertisement
Guest User

Untitled

a guest
Oct 12th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.46 KB | None | 0 0
  1. type Tree =
  2.     | Empty
  3.     | Node of int * Tree * Tree
  4.  
  5. let rec insert tree v =
  6.     match tree with
  7.     | Node(v0, left, right) when v<v0 -> Node(v0, (insert left v), right)
  8.     | Node(v0, left, right) when v>v0 -> Node(v0, left, (insert right v))
  9.     | Empty -> Node(v, Empty, Empty)
  10.  
  11. let rec printTree tree =
  12.     match tree with
  13.     | Empty -> ()
  14.     | Node(v, left, right) ->
  15.         printTree left
  16.         printfn "%d" v
  17.         printTree right
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement