Jump to content

Algebraic data types: Difference between revisions

m
(OCaml solution)
Line 32:
type 'a tree = E | T of color * 'a tree * 'a * 'a tree
(** val balance :: color ->* 'a tree ->* 'a ->* 'a tree -> 'a tree *)
let balance = function
| (B, T (R, T (R,a,x,b), y, c), z, d) -> T (R, T (B,a,x,b), y, T (B,c,z,d))
| (B, T (R, a, x, T (R,b,y,c)), z, d) -> T (R, T (B,a,x,b), y, T (B,c,z,d))
| (B, a, x, T (R, T (R,b,y,c), z, d)) -> T (R, T (B,a,x,b), y, T (B,c,z,d))
| (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))
| (col, a, x, b) -> T (col, a, x, b)
(** val insert :: 'a -> 'a tree -> 'a tree *)
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.