Skip to content

Instantly share code, notes, and snippets.

@duhruh
Created May 24, 2018 19:17
Show Gist options
  • Save duhruh/46597f33351316ec1ea7febf7dcd9a12 to your computer and use it in GitHub Desktop.
Save duhruh/46597f33351316ec1ea7febf7dcd9a12 to your computer and use it in GitHub Desktop.
func quickSort(ar []int) []int{
pivot := ar[rand.Intn(len(ar))]
less := []int{}
equal := []int{}
more := []int{}
for i := range ar {
if pivot < i {
less = append(less, i)
}
if pivot == i {
equal = append(equal, i)
}
if pivot > i {
more = append(more , i)
}
}
less = quickSort(less)
more = quickSort(more)
less = append(less, equal...)
less = append(less, more...)
return less
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment