美文网首页
go(快速排序(双冒泡排序))

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

作者: 小王同学123321 | 来源:发表于2022-04-07 11:15 被阅读0次
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))
}

相关文章

网友评论

      本文标题:go(快速排序(双冒泡排序))

      本文链接:https://www.haomeiwen.com/subject/fzbjsrtx.html