You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
404 B
21 lines
404 B
5 years ago
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
func main() {
|
||
|
fmt.Println(quicksort([]int{1, 8, 5, 3, 4, 9}))
|
||
|
}
|
||
|
|
||
|
// start-quicksort
|
||
|
func quicksort(p []int) []int {
|
||
|
if len(p) == 0 {
|
||
|
return []int{}
|
||
|
}
|
||
|
|
||
|
lesser := filter(func(x int) bool { return p[0] > x }, p[1:])
|
||
|
greater := filter(func(x int) bool { return p[0] <= x }, p[1:])
|
||
|
|
||
|
return append(quicksort(lesser), prepend(p[0], quicksort(greater))...)
|
||
|
}
|
||
|
// end-quicksort
|