type inttree = Nil | T of inttree * int * inttree

let insert v =
  let rec insv = function
  | Nil -> T(Nil, v, Nil)
  | T (left, n, right) -> if v < n then T(insv left, n, right)
                          else T(left, n, insv right)
  in insv

let tree_of_list = List.fold_left (fun t v -> insert v t) Nil 

let list_of_tree =
  let rec append lst = function
    | Nil -> lst
    | T (left, n, right) -> append (n :: append lst right) left
  in append []

let sort lst = list_of_tree (tree_of_list lst)


                            

This document was generated using caml2html