open Printf
       
type 'a cbtree = L of 'a | T of 'a cbtree * 'a * 'a cbtree

let rec height = function
  | L _ -> 0
  | T (l, _, r) -> 1 + max (height l) (height r)

let rec nodecnt = function
  | L _ -> 1
  | T (l, _, r) -> 1 + nodecnt l + nodecnt r

let inorder =                                           
  let rec inord cnt = function
    | L v -> printf "%d: %d\n" cnt v; cnt + 1
    | T (l, v, r) -> let cnt1 = inord cnt l in
                   printf "%d: %d\n" cnt1 v; inord (cnt1+1) r
  in inord 1

let t = T (L 4, 6, T(T(L 2, 5, L 3), 7, L 9))
;;
ignore (inorder t)
          

This document was generated using caml2html