Advertisement
Guest User

Juliet

a guest
Nov 13th, 2009
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.36 KB | None | 0 0
  1. (* Prints a binary tree sideways *)
  2.  
  3. type 'a tree =
  4.     | Node of 'a tree * 'a * 'a tree
  5.     | Nil
  6.  
  7. let rec print t =
  8.     let rec loop n = function
  9.         | Nil -> ()
  10.         | Node(l, x, r) ->
  11.             let spaces = new System.String(' ', n * 4)
  12.             loop (n + 1) r
  13.             printfn "%s%A" spaces x
  14.             loop (n + 1) l
  15.     loop 0 t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement