Go语言实现选择法排序

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

package main

import "fmt"

func select_sort(a []int) {
	len := len(a)
	for i:=0; i < len-1; i++ {
		k := i
		j:= i + 1		
		for ; j < len; j++ {
			if a[j] < a[k] { k = j }
		}
		if k != i {
			a[i], a[k] = a[k], a[i] 
		}
	}
}

func print_array(a []int) {
	for i := 0; i < len(a) - 1; i++ {
		fmt.Printf("%d, ", a[i])
	}
	fmt.Print(a[len(a)-1])
}

func main() {
	a := []int{1, 8, 5, 9, 4, 3, 6, 6}
	print_array(a)
	fmt.Printf("\n")
	select_sort(a)
	print_array(a)
}