26 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Modula-2
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Modula-2
		
	
	
	
	
	
| 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.
 |