go 快排

2022-02-09  本文已影响0人  晓得为_
package main

import "fmt"

func main() {
    testSort()
}

func testSort() {
    slicData := []int{3, 2, 4, 5, 6, 6, 7, 8, 3, 2, 1}
    fmt.Println("brfore", slicData)

    quickSortRefer(slicData, 0, len(slicData)-1)
    fmt.Println("brfore", slicData)
}

func quickSortRefer(slicData []int, strt int, end int) {
    l := strt
    r := end
    if r > l {
        mid := slicData[l]
        for l < r {
            for (l < r) && mid <= slicData[r] {
                r--
            }
            slicData[l] = slicData[r]
            slicData[r] = mid

            for (l < r) && mid >= slicData[l] {
                l++
            }
            slicData[r] = slicData[l]
            slicData[l] = mid

        }
        quickSortRefer(slicData, 0, l-1)
        quickSortRefer(slicData, l+1, end)
    }
}

func test1() {
    list := []int{1, 2, 3}
    var res *int
    for k, v := range list {
        if v == 1 {
            fmt.Println("33333333", k, v)
            res = &list[k]
        }
    }
    fmt.Println("33333333", *res)
}
上一篇下一篇

猜你喜欢

热点阅读