Add elements in 'a tree in Ocaml -
so, here problem.. need write function add elements in tree , binary tree, must organized. problem in how tree defined. have tree:
type 'a tree = { mutable cont:'a; mutable left:'a bin_tree; mutable right:'a bin_tree } , 'a bin_tree = empty |node of 'a bin_tree;; so, when write function add elements in tree says tree of type 'a tree , using function 'a bin_tree.
i tried lot of different ways write function , same error. function used last is:
let rec dodajvdrevo x = function empty -> node{cont=x; left=empty; right=empty} |node{cont; left; right} -> if x < cont node{cont; left= dodajvdrevo x left; right} else if x > cont node{cont; left; right = dodajvdrevo x right} else node{cont; left; right};; please me , give clues.
thank you!
the node constructor should take 'a tree instead of 'a bin_tree.
Comments
Post a Comment