Skip to content

Instantly share code, notes, and snippets.

@lkrych
Created July 29, 2018 18:21
Show Gist options
  • Save lkrych/48d5b6fcfd3731641afb96f0f4ea2940 to your computer and use it in GitHub Desktop.
Save lkrych/48d5b6fcfd3731641afb96f0f4ea2940 to your computer and use it in GitHub Desktop.
quickSort demo
func quickSort(strings []string) []string {
if len(strings) <= 1 {
return strings
}
pivot := strings[0]
left := []string{}
right := []string{}
for i := 1; i < len(strings); i++ {
currString := strings[i]
if currString > pivot {
right = append(right, currString)
} else {
left = append(left, currString)
}
}
sortedLeft := quickSort(left)
sortedRight := quickSort(right)
sorted := append(sortedLeft, pivot)
sorted = append(sorted, sortedRight...)
return sorted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment