Created
July 29, 2018 18:21
-
-
Save lkrych/48d5b6fcfd3731641afb96f0f4ea2940 to your computer and use it in GitHub Desktop.
quickSort demo
This file contains hidden or 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
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