String Sort Routines: Quick, Merge, Selection, and Insert Sort

Category:
Lists, Collections and Arrays
Type:
Modules
Difficulty:
Intermediate
Author:
Phil Fresle

Version Compatibility:

More information:
Generic string sort routines. I prefer to use the 'non-pure' Quick Sort unless you have a good reason to choose another routine.

Here are the routines in order of efficiency.

  • Quick Sort: Fast for large arrays - delegates to insert sort when called with a small array and to sort small chunks of the large array. This 'non-pure' quick sort is therefore quicker by not recursing for small chunks where a simple brute-force iteration is quicker.
  • Merge Sort: Fast for large arrays - larger memory footprint than QuickSort. Delegates to insert sort for small arrays.
  • Insert Sort: Fast for small arrays (say less than 60 values)
  • Selection Sort: Fast for small arrays (say less than 60 values)
NOTE: Due to the recursive nature of Quick and Merge sort they are not very efficient for small arrays which is why the routines delegate to a more brute force insert sort for small arrays.

Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.

Download stringsort.zip