Commit f4ff999e authored by Giuseppe Castagna's avatar Giuseppe Castagna
Browse files

Added examples of the appendix

parent f17a49ea
......@@ -12,6 +12,7 @@ type Wrongtree('a) = <red elem='a>( [ Rtree('a) Btree('a) ]
type Unbalanced('a) = <black elem='a>( [ Wrongtree('a) RBtree('a) ]
| [ RBtree('a) Wrongtree('a) ])
;;
(* does not type *)
let balance ( Unbalanced('a) -> Rtree('a) ; 'b\Unbalanced('a) -> 'b\Unbalanced('a) )
......@@ -48,6 +49,15 @@ type UTree = <black (Any)>[ <red (Any)>[ <red (Any)>[ Any Any ] Any ] Any ]
;;
let balance ( Unbalanced('a) -> Rtree('a) ; 'b\UTree -> 'b\UTree )
| <black (z)>[ <red (y)>[ <red (x)>[ a b ] c ] d ]
| <black (z)>[ <red (x)>[ a <red (y)>[ b c ] ] d ]
| <black (x)>[ a <red (z)>[ <red (y)>[ b c ] d ] ]
| <black (x)>[ a <red (y)>[ b <red (z)>[ c d ] ] ] ->
<red (y)>[ <black (x)>[ a b ] <black (z)>[ c d ] ]
| x -> x
;;
let insert (x : 'a) (t : Btree('a)) : Btree('a) =
let ins_aux ( [] -> Rtree('a);
Btree('a)\[] -> RBtree('a)\[];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment