home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 061-070 / amok66 / sorting / sorting.def < prev    next >
Encoding:
Modula Definition  |  1993-11-04  |  2.5 KB  |  68 lines

  1. (******************************************************************************
  2.  
  3.     :Program.    Sorting.def
  4.     :Contents.   procedure for sorting
  5.     :Revision.   1
  6.     :Date.       15.11.91 --- 14:14 --- [UHU]
  7.     :Author.     Markus Uhlendahl
  8.     :Address.    Vorm Burgtor 16, D-4408 Dülmen
  9.     :Phone.      02594/81540
  10.     :Language.   Modula-2
  11.     :Translator. M2Amiga 4.0d
  12.     :Copyright.  Public Domain
  13.     :History.    15.11.91 --- 1.0 --- first release
  14.  
  15. ******************************************************************************)
  16. DEFINITION MODULE Sorting;
  17.  
  18.  
  19. TYPE
  20.   SwapProcedure=PROCEDURE (LONGINT,LONGINT);
  21. (*
  22.  * FUNCTION     swap two elements of an array
  23.  *              Swaps two elements of an array.
  24.  * INPUTS       LONGINT = index of an element in the array
  25.  *              LONGINT = index of an element in the array
  26.  *
  27.  *)
  28.   Comparison=PROCEDURE (LONGINT,LONGINT) : BOOLEAN;
  29. (*
  30.  * FUNCTION     compare two elements
  31.  *              Compares two elements of an array.
  32.  * INPUTS       LONGINT = index of an element in the array
  33.  *              LONGINT = index of an element in the array
  34.  * RESULTS      TRUE if the comparison is TRUE else FALSE
  35.  *
  36.  *)
  37.  
  38.  
  39. PROCEDURE QuickSort (first,last : LONGINT;
  40.                      Lower      : Comparison;
  41.                      Swap       : SwapProcedure;
  42.                      ascending  : BOOLEAN);
  43. (*
  44.  * FUNCTION     sort an array
  45.  *              This implementation of the quicksort-algorythm is very
  46.  *              flexible. It sorts arrays of every type and the user can
  47.  *              choose if the array is sorted ascending or not. To make this
  48.  *              possible the user has to write two procedures. One that
  49.  *              compares two elements of the array and one that swaps two
  50.  *              elements.
  51.  * INPUTS       first = first index of the array
  52.  *              last = last index of the array
  53.  *              Lower = PROCEDURE which compares two elements of the array
  54.  *                      returns TRUE if the first element of the comparison
  55.  *                      is really lower (a<b) than the second element
  56.  *              Swap = PROCEDURE which swaps two elements of the array
  57.  *              ascending = if ascending is TRUE the first element of the
  58.  *                          array will be the smallest and the last element
  59.  *                          the greatest
  60.  *                          if ascending is FALSE it will be vice versa
  61.  * BUGS         none known
  62.  * AUTHOR       Markus Uhlendahl
  63.  *
  64.  *)
  65.  
  66.  
  67. END Sorting.
  68.