quicksort.a68

     
   1  COMMENT
   2  
   3  @section Synopsis
   4  
   5  The well-known recursive quicksort algorithm.
   6  
   7  COMMENT
   8  
   9  MODE TREE = REF NODE,
  10       NODE = STRUCT (LONG REAL x, TREE s, l);
  11  
  12  TREE empty = NIL,
  13  PROC new leaf = (LONG REAL x) TREE: HEAP NODE := (x, empty, empty);
  14  
  15  OP WRITE = (TREE t) VOID:
  16     IF t ISNT empty
  17     THEN WRITE s OF t;
  18          print ((x OF t, space));
  19          WRITE l OF t
  20     FI;
  21  
  22  OP +:= = (REF TREE t, LONG REAL x) VOID:
  23     IF t IS empty
  24     THEN t := new leaf (x)
  25     ELSE (x < x OF t | s OF t | l OF t) +:= x
  26     FI;
  27  
  28  TREE list := empty;
  29  TO read int
  30  DO list +:= long next random
  31  OD;
  32  WRITE list
     


© 2002-2024 J.M. van der Veer (jmvdveer@xs4all.nl)