String Sort Routines: Quick, Merge, Selection, and Insert Sort
Category:Lists, Collections and Arrays
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)
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.