golang数据结构之快速排序
具体过程:黑色标记代表左指针,红色标记代表右指针,蓝色标记代表中间值。(依次从左往向下)
//QuickSort 快速排序 func QuickSort(left int, right int, arr *[7]int) { l := left r := right pivot := arr[(left+right)/2] tmp := 0 for l < r { for arr[l] < pivot { l++ } for arr[r] > pivot { r-- } if l >= r { break } tmp = arr[l] arr[l] = arr[r] arr[r] = tmp if arr[l] == pivot { r-- } if arr[r] == pivot { l++ } } if l == r { l++ r-- } if left < r { QuickSort(left, r, arr) } if right > l { QuickSort(l, right, arr) } }
相关推荐
Masimaro 2020-06-21
Joymine 2020-06-06
清溪算法君老号 2020-06-01
GhostLWB 2020-04-20
田有朋 2020-04-19
sunjunior 2020-04-10
cmsmdn 2020-03-03
shenwenjie 2020-02-26
sunjunior 2020-02-15
hanyujianke 2020-01-13
路漫 2020-01-12
sunnyJam 2019-12-31
KilluaZoldyck 2019-12-15
yuanran0 2019-12-14
Happyunlimited 2019-12-10
baike 2019-12-09
yishujixiaoxiao 2019-12-02
YUAN 2019-11-19
alicelmx 2019-11-12