public
Created

Quick OCaml tree example

  • Download Gist
tree.ml
OCaml
1 2 3 4 5 6 7 8 9 10 11 12
type tree = Node of tree * int * tree | Nil
 
open Printf
let rec print_tree t =
match t with
| Node (left, data, right) -> print_tree left;
printf "%d\n" data;
print_tree right
| Nil -> ();;
 
 
print_tree (Node (Node (Nil, 1, Nil), 3, Node (Nil, 2, Nil)))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.