<Keyword>datatype</Keyword><Normal Text> Colour = R | B</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Keyword>datatype</Keyword><Normal Text> 'a RBtree = E | N </Normal Text><Keyword>of</Keyword><Normal Text> Colour * 'a * 'a RBtree * 'a RBtree</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Comment>(* Dieses lookup funktioniert nur fuer Elemente vom Typ int *)</Comment><br/>
<Normal Text></Normal Text><br/>
<Keyword>fun</Keyword><Normal Text> lookup (x,E) = </Normal Text><Keyword>false</Keyword><br/>
<Normal Text>  | lookup (x,N(_,y,l,r)) = </Normal Text><br/>
<Normal Text>       </Normal Text><Keyword>if</Keyword><Normal Text> x < y </Normal Text><Keyword>then</Keyword><Normal Text> lookup(x,l)</Normal Text><br/>
<Normal Text>       </Normal Text><Keyword>else</Keyword><Normal Text> </Normal Text><Keyword>if</Keyword><Normal Text> y < x </Normal Text><Keyword>then</Keyword><Normal Text> lookup(x,r)</Normal Text><br/>
<Normal Text>       </Normal Text><Keyword>else</Keyword><Normal Text> </Normal Text><Keyword>true</Keyword><br/>
<Normal Text></Normal Text><br/>
<Keyword>fun</Keyword><Normal Text> balance (B,x,N(R,y,N(R,z,t1,t2),t3),t4) =</Normal Text><br/>
<Normal Text>       N(R,y,N(B,z,t1,t2),N(B,x,t3,t4))</Normal Text><br/>
<Normal Text>  | balance (B,x,N(R,y,t1,N(R,z,t2,t3)),t4) =</Normal Text><br/>
<Normal Text>       N(R,z,N(B,y,t1,t2),N(B,x,t3,t4))</Normal Text><br/>
<Normal Text>  | balance (B,x,t1,N(R,y,N(R,z,t2,t3),t4)) =</Normal Text><br/>
<Normal Text>       N(R,z,N(B,x,t1,t2),N(B,y,t3,t4))</Normal Text><br/>
<Normal Text>  | balance (B,x,t1,N(R,y,t2,N(R,z,t3,t4))) =</Normal Text><br/>
<Normal Text>       N(R,y,N(B,x,t1,t2),N(B,z,t3,t4))</Normal Text><br/>
<Normal Text>  | balance t = N t</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Keyword>fun</Keyword><Normal Text> insert(x,t) =</Normal Text><br/>
<Normal Text>   </Normal Text><Keyword>let</Keyword><br/>
<Normal Text>      </Normal Text><Keyword>fun</Keyword><Normal Text> ins E = N(R,x,E,E)</Normal Text><br/>
<Normal Text>        | ins (t </Normal Text><Keyword>as</Keyword><Normal Text> N(c,y,l,r)) = </Normal Text><br/>
<Normal Text>             </Normal Text><Keyword>if</Keyword><Normal Text> x < y </Normal Text><Keyword>then</Keyword><Normal Text> balance (c,y,ins l,r)</Normal Text><br/>
<Normal Text>             </Normal Text><Keyword>else</Keyword><Normal Text> </Normal Text><Keyword>if</Keyword><Normal Text> y < x </Normal Text><Keyword>then</Keyword><Normal Text> balance (c,y,l,ins r)</Normal Text><br/>
<Normal Text>             </Normal Text><Keyword>else</Keyword><Normal Text> t</Normal Text><br/>
<Normal Text>      </Normal Text><Keyword>val</Keyword><Normal Text> N(_,y,l,r) = ins t</Normal Text><br/>
<Normal Text>   </Normal Text><Keyword>in</Keyword><Normal Text> N(B,y,l,r)</Normal Text><br/>
<Normal Text>   </Normal Text><Keyword>end</Keyword><br/>
