4 Star 9 Fork 6

ShirDon-廖显东/零基础Go语言算法实战源码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
interview7-9.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 10个月前 . first commit
// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++
package main
import (
"fmt"
"math/rand"
)
func ArraySort(array []int) []int {
quickSortDesc(array, 0, len(array)-1)
return array
}
func quickSortDesc(array []int, low, high int) {
if low >= high {
return
}
k := rand.Intn(high-low+1) + low
tmp := array[high]
array[high] = array[k]
array[k] = tmp
pivot := array[high]
j := low - 1
for i := low; i < high; i++ {
if array[i] >= pivot {
j++
tmp := array[j]
array[j] = array[i]
array[i] = tmp
}
}
tmp = array[j+1]
array[j+1] = array[high]
array[high] = tmp
quickSortDesc(array, low, j)
quickSortDesc(array, j+1, high)
}
func main() {
array := []int{33, 23, 56, 7, 8, 18, 99, 28}
res := ArraySort(array)
fmt.Println(res)
}
//$ go run interview6-9.go
//[99 56 33 28 23 18 8 7]
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAlgorithms.git
git@gitee.com:shirdonl/goAlgorithms.git
shirdonl
goAlgorithms
零基础Go语言算法实战源码
3e77a12194dd

搜索帮助