Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | |
2 | datatype ilist = nill | cons of int * ilist | |
3 | ||
4 | fun f Xs = | |
5 | case Xs of | |
6 | nill => nill | |
7 | | cons( z, zs ) => | |
8 | let | |
9 | fun g( a, b, c, ds ) = | |
10 | case ds of | |
11 | nill => cons( c, nill ) | |
12 | | cons( e, es ) => | |
13 | case ( e < b ) of | |
14 | false => cons( c, ds ) | |
15 | | true => | |
16 | cons( | |
17 | e, | |
18 | case ( z < a ) of | |
19 | false => | |
20 | g( b, c, c, es ) | |
21 | | true => cons( c, nill ) | |
22 | ) | |
23 | in | |
24 | case zs of | |
25 | nill => Xs | |
26 | | cons( y, ys ) => | |
27 | g( | |
28 | z, | |
29 | z, | |
30 | z, | |
31 | f( g( z, z, y, ys ) ) | |
32 | ) | |
33 | end | |
34 | ||
35 | fun print_ilist( nill ) = print "\n" | |
36 | | print_ilist( cons( X, Xs ) ) = ( print (Int.toString X ^ " "); print_ilist Xs ) | |
37 | ||
38 | val Input = cons( 6, cons( 5, cons( 7, cons( 3, cons( 1, cons( 2, cons( 4, nill ) ) ) ) ) ) ) | |
39 | ||
40 | val _ = print_ilist( f Input ) |