| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 4 |
<title>highlight.sml</title> |
| 5 |
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (SML) - Theme (Breeze Light)"/> |
| 6 |
</head><body style="background-color:#ffffff;color:#1f1c1b"><pre> |
| 7 |
<span style="font-weight:bold;">datatype</span> Colour = R | B |
| 8 |
|
| 9 |
<span style="font-weight:bold;">datatype</span> 'a RBtree = E | N <span style="font-weight:bold;">of</span> Colour * 'a * 'a RBtree * 'a RBtree |
| 10 |
|
| 11 |
<span style="color:#898887;">(* Dieses lookup funktioniert nur fuer Elemente vom Typ int *)</span> |
| 12 |
|
| 13 |
<span style="font-weight:bold;">fun</span> lookup (x,E) = <span style="font-weight:bold;">false</span> |
| 14 |
| lookup (x,N(_,y,l,r)) = |
| 15 |
<span style="font-weight:bold;">if</span> x < y <span style="font-weight:bold;">then</span> lookup(x,l) |
| 16 |
<span style="font-weight:bold;">else</span> <span style="font-weight:bold;">if</span> y < x <span style="font-weight:bold;">then</span> lookup(x,r) |
| 17 |
<span style="font-weight:bold;">else</span> <span style="font-weight:bold;">true</span> |
| 18 |
|
| 19 |
<span style="font-weight:bold;">fun</span> balance (B,x,N(R,y,N(R,z,t1,t2),t3),t4) = |
| 20 |
N(R,y,N(B,z,t1,t2),N(B,x,t3,t4)) |
| 21 |
| balance (B,x,N(R,y,t1,N(R,z,t2,t3)),t4) = |
| 22 |
N(R,z,N(B,y,t1,t2),N(B,x,t3,t4)) |
| 23 |
| balance (B,x,t1,N(R,y,N(R,z,t2,t3),t4)) = |
| 24 |
N(R,z,N(B,x,t1,t2),N(B,y,t3,t4)) |
| 25 |
| balance (B,x,t1,N(R,y,t2,N(R,z,t3,t4))) = |
| 26 |
N(R,y,N(B,x,t1,t2),N(B,z,t3,t4)) |
| 27 |
| balance t = N t |
| 28 |
|
| 29 |
<span style="font-weight:bold;">fun</span> insert(x,t) = |
| 30 |
<span style="font-weight:bold;">let</span> |
| 31 |
<span style="font-weight:bold;">fun</span> ins E = N(R,x,E,E) |
| 32 |
| ins (t <span style="font-weight:bold;">as</span> N(c,y,l,r)) = |
| 33 |
<span style="font-weight:bold;">if</span> x < y <span style="font-weight:bold;">then</span> balance (c,y,ins l,r) |
| 34 |
<span style="font-weight:bold;">else</span> <span style="font-weight:bold;">if</span> y < x <span style="font-weight:bold;">then</span> balance (c,y,l,ins r) |
| 35 |
<span style="font-weight:bold;">else</span> t |
| 36 |
<span style="font-weight:bold;">val</span> N(_,y,l,r) = ins t |
| 37 |
<span style="font-weight:bold;">in</span> N(B,y,l,r) |
| 38 |
<span style="font-weight:bold;">end</span> |
| 39 |
</pre></body></html> |