/**
* Recursive insertion sort --- NOT the recommended formulation ! ! !
*/
public static void insSort ( Comparable[] x, int n )
{ int lim = n-1, // last entry in the array
hole; // insertion point in sorted region
Comparable save = x[lim]; // Item being positioned
if ( n > 1 )
{ insSort ( x, n-1 ); // Recursively sort the front end
// Position save between x[lim] and x[0]
for ( hole = lim ;
hole > 0 && save.compareTo(x[hole-1]) < 0 ;
hole-- )
{ x[hole] = x[hole-1]; }
x[hole] = save; // Plug the hole with save
} // else is ignored --- array of 0 or 1 entries is already sorted
} // end insSort()
/**
* Recursive selection sort --- NOT the recommended formulation ! ! !
*/
public static void selSort ( Comparable[] x, int size )
{ if ( size > 1 )
{ int j = maxIdx ( x, size ); // Subscript of largest entry
swap ( x, size-1, j ); // Move to end of the array
selSort ( x, size-1 ); // Recursively sort the front end
} // else is ignored --- array of 0 or 1 entries is already sorted
} // end selSort()