Changeset 3985


Ignore:
Timestamp:
Oct 21, 2008, 1:19:25 PM (12 years ago)
Author:
orlov
Message:
  • Added SortBy? and Sort functions (implemented by merge-sort algorithm).
Location:
to-imperative/trunk/java/refal/refal/plus
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/refal/refal/plus/List.rf

    r3964 r3985  
    164164};
    165165
     166SortBy s.compare e.list =
     167  <Length e.list> :: s.len,
     168  {
     169    <Le (s.len) (1)> = e.list;
     170    <Div s.len 2> :: s.k =
     171      <Merge s.compare (<SortBy s.compare <Left 0 s.k e.list>>) (<SortBy s.compare <Middle s.k 0 e.list>>)>;
     172  };
     173
     174$func Merge s.compare (e.left) (e.right) = e.merged_list;
     175Merge s.compare (e.left) (e.right) = {
     176  e.left  : /*empty*/ = e.right;
     177  e.right : /*empty*/  = e.left;
     178  e.left : t.l e.left_rest, e.right : t.r e.right_rest = {
     179    <Apply s.compare (t.l) (t.r)> : '<' = t.l <Merge s.compare (e.left_rest) (e.right)>;
     180    t.r <Merge s.compare (e.left) (e.right_rest)>;
     181  };
     182};
     183
     184Sort e.list = <SortBy &Compare e.list>;
     185
    166186/*
    167187 * Returns number of e.expr entries in e.source and e.source without all e.expr's.
  • to-imperative/trunk/java/refal/refal/plus/List.rfi

    r3964 r3985  
    4141$func Replicate s.n e.expr = e.list;
    4242
    43 $func QSort e.list = e.list;
     43$func QSort e.list = e.sorted_list;
     44
     45$func SortBy s.compare e.list = e.sorted_list;
     46
     47$func Sort e.list = e.sorted_list;
    4448
    4549// Returns number of e.expr entries in e.source and e.source without all e.expr's.
Note: See TracChangeset for help on using the changeset viewer.