Created
May 24, 2018 19:17
-
-
Save duhruh/46597f33351316ec1ea7febf7dcd9a12 to your computer and use it in GitHub Desktop.
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(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