source: applications/trunk/UGPSummerSchool2008/src/Sort.rf @ 3840

Last change on this file since 3840 was 3840, checked in by yura, 12 years ago
  • Program text for Alien.
  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 871 bytes
Line 
1$module Sort;
2
3$use Compare StdIO;
4
5$func Sort e.list = e.list;
6
7Sort {
8        /* empty */   = /* empty */;
9        s.head e.tail = <Split s.head e.tail> :: (e.smaller) (e.greater),
10                <Sort e.smaller> s.head <Sort e.greater>;
11};
12
13$func Split s.num e.list = (e.list) (e.list);
14
15Split s.num e.list, e.list : {
16        /* empty */   = () ();
17        s.head e.tail = <Split s.num e.tail> :: (e.smaller) (e.greater), {
18                <Le (s.head) (s.num)> = (s.head e.smaller) (e.greater);
19                (e.smaller) (s.head e.greater);
20        };
21};
22
23$func Main = e;
24
25Main, <WriteLn <Sort 1 5 2 5 2 1>>;
26
27
28
29$func Split2 s.num e.list = (e.list) (e.list);
30
31Split2 s.num e.list,
32        () () (e.list) $iter {
33                e.list : s.head e.tail, {
34                        <Le (s.head) (s.num)>,
35                                (e.smaller s.head) (e.greater) (e.tail);
36                        (e.smaller) (e.greater s.head) (e.tail);
37                };
38        } :: (e.smaller) (e.greater) (e.list),
39        e.list : /*empty*/,
40        (e.smaller) (e.greater);
Note: See TracBrowser for help on using the repository browser.