Skip to content

Instantly share code, notes, and snippets.

@educartoons
Created June 24, 2020 04:34
Show Gist options
  • Save educartoons/0b8021a665c21363bf0e12a73b31620f to your computer and use it in GitHub Desktop.
Save educartoons/0b8021a665c21363bf0e12a73b31620f to your computer and use it in GitHub Desktop.
Implementation of Quick Sort in Go
// We will call quicksort with
// quickSort(array, 0, len(array)-1)
func quickSort(A []int, p int, r int) []int {
if p < r {
var q = partition(A, p, r)
quickSort(A, p, q-1)
quickSort(A, q+1, r)
}
return A
}
func partition(A []int, p int, r int) int {
var x = A[r]
var i = p - 1
for j := p; j < r; j++ {
if A[j] <= x {
i = i + 1
A[i], A[j] = A[j], A[i]
}
}
A[i+1], A[r] = A[r], A[i+1]
return i + 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment