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

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