Skip to content

Instantly share code, notes, and snippets.

@mykoweb
Created February 13, 2017 00:02
Show Gist options
  • Save mykoweb/3731ba4d0b8615528fe1dbb50827e643 to your computer and use it in GitHub Desktop.
Save mykoweb/3731ba4d0b8615528fe1dbb50827e643 to your computer and use it in GitHub Desktop.
// 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