手记

简单选择排序(golang)

         

func simpleSelectionSort(unsorted []int, n int) {    var key, temp int    for i:=0; i<n; i++ {        key = selectMiniKey(unsorted, n, i)        if key!=i {            temp = unsorted[i]            unsorted[i] = unsorted[key]            unsorted[key] = temp        }    }}func selectMiniKey(a []int, n int, i int) int {    k:=i    for j := i+1; j<n; j++ {        if a[k] > a[j] {            k = j        }    }    return k}


0人推荐
随时随地看视频
慕课网APP