An illustration of the Mergesort algorithm. The "ref array c" means that the variable "c" is an array and that the call is "by reference", i.e., entries of c can be changed by this procedure and the changes will "stick". merge( ref array c, array a, int na, array b, int nb) { // This routine copies the entries of arrays a and b into c so that // the entries of c are sorted in increasing order. It assumes // that the elements of a and b are sorted already. if ( ( na < 1 ) or ( nb < 1 ) ) { cout << "You dummy." << endl; // Useless error message that won't help // you figure out what's wrong. ia = 1; // index into the a array. ib = 1; ic = 1; while (1) { // Repeat until ia > na or ib > nb. if ( a(ia) < b(ib) ) { // The smallest uncopied element is from a. c(ic) = a(ia); ia = ia + 1; ic = ic + 1; // (?? Write c(ic++) = a(ia++) in C ??) if ( ia > na ) { // If that was the last entry in a, copy the ... while ( ib <= nb ) { // rest of b into c ... c(ic) = b(ib); ic = ic + 1; ib = ib + 1; } return; // Then you're done. } } // Done with the case a(ia) < b(ib). else { // The smallest uncopied element is from b. c(ic) = b(ib); ib = ib + 1; ic = ic + 1; // (?? Write c(ic++) = b(ib++) in C ??) if ( ib > nb ) { // If that was the last entry in b, copy the ... while ( ia <= na ) { // rest of a into c ... c(ic) = a(ia); ic = ic + 1; ia = ia + 1; } return; // Then you're done. } } // Done with the case a(ia) >= b(ib). } // End of the main while(1) loop. cout << "You should not be here." << endl; // Equally useful message. return; } // End of the definition of the merge procedure. mergesort( ref array a, na, ref array t) { // Rearrange the elements of a to be in ascending order using the merge sort // algorithm. // na = the number of elements of a to be sorted = the number of elements of t needed. // a = the unsorted numbers on call, the same numbers sorted on return. // t = a scratch array of na elements. These will be changed. if ( n = 1 ) return; // A single number need not be sorted. if ( n < 1 ) { "ouch" } m = (int) n/2; // The size of the top sub array. nMm = n - m; // The size of the bottom sub array. a_top = the array with elements [ a( 1 ), ... , a(m) ]; // first half of the t_top = the array with elements [ t( 1 ), ... , t(m) ]; // data and scratch. a_bot = the array with elements [ a(m+1), ... , a(n) ]; // See below for t_bot = the array with elements [ t(m+1), ... , t(n) ]: // explination for ( ia = 1, ..., m ) t_top(ia) = a_top(ia); // Copy the top half out and mergesort( t_top, m, a_top); // sort it. for ( ia = 1, ..., nMm ) t_bot(ia) = a_bot(ia); // Likewise for the bottom. mergesort( t_bot, nMm, a_bot); // merge ( a, t_top, m, t_bot, nMm ); return; } Explination of the a_top = .... stuff: I want a_top to be an array whose elements coincide in memory with the first part or the a array. Is this bad programming practice? In C, you would write "a_top = a; a_bot = &(a[nMm-1]);" In FORTRAN, "mergesort( t_bot, nMm, a_bot);" would be replaced by: call mrgsrt( t(nmm), nmm, a(nmm) ) I don't think anything like this is possible in Pascal.