home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / isetl / qstack.t < prev    next >
Encoding:
Text File  |  1987-08-20  |  965 b   |  50 lines

  1. program quick;
  2.  
  3.     s := om;
  4.     while s /= [] do
  5.     print "enter set to be sorted";
  6.     read  s;
  7.     print s;
  8.  
  9.     $work = list of tuples to be sorted and catenated after result
  10.     work   := [ [x : x in s] ];
  11.     result := [];
  12.  
  13.     while work /= [] do 
  14.         next := work(1);
  15.         work := work(2..);
  16.  
  17.         if #next <= 1 then
  18.         result := result + next;
  19.         else
  20.         pivot := next(1);
  21.         work := [ [y: y in next| y < pivot],
  22.               [pivot],
  23.               [y: y in next| y > pivot]
  24.             ] + work;
  25.         end;
  26.     end;
  27.  
  28.     print result;
  29.     end;
  30.  
  31. end;
  32.  
  33. [20,19..1];
  34. "qwertyuioplkjhgfdsazxcvbnm";
  35. $ worst case data is sorted
  36. [1..20];
  37. [20,19..1];
  38.  
  39. $random data is faster
  40. [25, 13, 14, 5, 6, 7, 22, 23, 24, 1, 2, 9, 27, 28, 34, 35, 26, 15,
  41. 37, 38, 40, 16, 17, 30, 31, 21, 10, 11, 18, 32, 33, 39, 29, 19, 3,
  42. 4, 8, 20, 12, 36];
  43.  
  44. $of course, strings work too
  45. ["there", "is", "hardly", "any", "problem", "with", "using",
  46. "different", "types", "in", "subtle", "because", "the", "operators",
  47. "are", "polymorphic"];
  48.  
  49.  [];
  50.