home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part01 / fproot / demo / QuickSort < prev    next >
Encoding:
Text File  |  1987-07-05  |  579 b   |  27 lines

  1. (*
  2.  * QuickSort
  3.  *
  4.  * This function sorts a sequence of numbers or strings into ascending order
  5.  * using the Quicksort algorithm.
  6.  *
  7.  * Examples:
  8.  *
  9.  *      <3 1 4 1 5 9 2> : QuickSort == <1 1 2 3 4 5 9>
  10.  *
  11.  *      <all work and no play> : QuickSort == <all and no play work>
  12.  *
  13.  * The sequence may not mix strings and numbers.
  14.  *)
  15.  
  16. DEF QuickSort AS
  17.    IF [length,#2] | < THEN id
  18.    ELSE
  19.       [id,1] | distr |
  20.       [      
  21.          FILTER < END | EACH 1 END | QuickSort,
  22.          FILTER = END | EACH 1 END,
  23.          FILTER > END | EACH 1 END | QuickSort
  24.       ] | cat
  25.    END;
  26.  
  27.