fork download
  1. type color = R | B
  2. type 'a tree = E | T of color * 'a tree * 'a * 'a tree
  3.  
  4. let balance = function
  5. | B, T (R, T (R,a,x,b), y, c), z, d
  6. | B, T (R, a, x, T (R,b,y,c)), z, d
  7. | B, a, x, T (R, T (R,b,y,c), z, d)
  8. | B, a, x, T (R, b, y, T (R,c,z,d)) -> T (R, T (B,a,x,b), y, T(B,c,z,d))
  9. | c, a, x, b -> T (c, a, x, b)
  10.  
  11. let insert x s =
  12. let rec ins = function
  13. | E -> T (R,E,x,E)
  14. | T (c,a,y,b) as s ->
  15. if x < y then
  16. balance (c, ins a, y, b)
  17. else if x > y then
  18. balance (c, a, y, ins b)
  19. else
  20. s
  21. in let T (_,a,y,b) -> ins s | E -> failwith "bad value"
  22. in T (B,a,y,b)
  23.  
  24. let rec member x = function
  25. | E -> false
  26. | T (_, left, y, right) ->
  27. x = y || (x < y && member x left) || (x > y && member x right)
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
File "prog.ml", line 21, characters 27-29:
Syntax error
stdout
Standard output is empty