Added the ArraySort module

This commit is contained in:
ceriel
1988-02-19 12:53:15 +00:00
parent e640d9f61c
commit a783d1ecee
5 changed files with 179 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
DEFINITION MODULE ArraySort;
(*
Module: Array sorting module
Author: Ceriel J.H. Jacobs
Date: $Header$
Interface is like the qsort() interface in C, so that an array of values
can be sorted. This does not mean that it has to be an ARRAY, but it does
mean that the values must be consecutive in memory, and the order is the
"memory" order.
The user has to define a comparison procedure of type CompareProc.
This routine gets two pointers as parameters. These are pointers to the
opbjects that must be compared. The sorting takes place in ascending order,
so that f.i. if the result of the comparison is "less", the first argument
comes in front of the second.
*)
FROM SYSTEM IMPORT ADDRESS; (* no generics in Modula-2, sorry *)
TYPE CompareResult = (less, equal, greater);
CompareProc = PROCEDURE(ADDRESS, ADDRESS): CompareResult;
PROCEDURE Sort(base: ADDRESS; (* address of array *)
nel: CARDINAL; (* number of elements in array *)
size: CARDINAL; (* size of each element *)
compar: CompareProc); (* the comparison procedure *)
END ArraySort.