go(快速排序(双冒泡排序))

2022-04-07  本文已影响0人  小王同学123321
func QuickSort(arr []int) []int{
    length := len(arr)
    if length <= 1{
        return arr
    }
    compare:=arr[0]
    low:=make([]int,0,0)
    high:=make([]int,0,0)
    mid:=make([]int,0,0)
    mid=append(mid,compare)
    for i:=1;i<length;i++{
        if arr[i] < compare{
            low=append(low,arr[i])
        } else if arr[i] > compare{
            high=append(high,arr[i])
        } else {
            mid=append(mid,arr[i])
        }

    }
    fmt.Println(low,high,mid)
    low,high=QuickSort(low),QuickSort(high)
    myarr := append(append(low,mid...),high...)
    return myarr
}

func main(){
    arr := []int{11,1,19,232,29, 30, 2, 5, 45, 8, 234, 12, 63}
    //fmt.Println(BubblesortMax(arr))
    fmt.Println(QuickSort(arr))
}
上一篇下一篇

猜你喜欢

热点阅读