Created
February 13, 2017 00:02
-
-
Save mykoweb/3731ba4d0b8615528fe1dbb50827e643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This version of QuickSort reverts to InsertionSort when the | |
// slice size is below a certain cutoff value. The cutoff value | |
// is parametrizable. | |
func QuickSort(data Interface, l int, r int, cutoff int) { | |
if l >= r { | |
return | |
} | |
if r-l > cutoff { | |
pivot := partition(data, l, r) | |
QuickSort(data, l, pivot-1, cutoff) | |
QuickSort(data, pivot+1, r, cutoff) | |
} else { | |
insertionSort(data, l, r) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment