Golang - SelectionSort
来源:互联网 发布:java 邮件发送excel 编辑:程序博客网 时间:2024/05/18 00:10
//We start selection sort by scanning the entire list to//find its smallest element and exchange it with the first//element, putting the smallest element in its final position in//the sorted list. Then we scan the list, starting with the second//element, to find the smallest among the last n-1 elements//and exchange it with the second element, putting the second//smallest element in its final position.//Generally, on the ith pass through the list, which we number from 0 to//n-2, the algorithm searches for the smallest item among the n-i elements//and swap it with A.//After n-1 passes, the list is sorted.package mainimport ( "fmt")//Sorts a given slice by selection sort//Input: A slice A[0..n-1] of orderable elements//Output: The original slice after sorted in nondecreasing orderfunc SelectionSort(A []int) []int { length := len(A) for i := 0; i < length-1; i++ { min := i for j := i + 1; j < length; j++ { if A[min] > A[j] { min = j } } A[i], A[min] = A[min], A[i] } return A}func main() { A := []int{1, 10, 9, 8, 7, 44, 2, 3, 33} fmt.Println("The slice before sorted : ", A) fmt.Println("The slice after sorted : ", SelectionSort(A))}
0 0
- Golang - SelectionSort
- SelectionSort
- selectionSort
- selectionSort
- selectionSort
- selectionSort
- SelectionSort
- selectionSort
- 选择排序SelectionSort
- 快速排序(SelectionSort)
- 选择排序-SelectionSort
- 选择排序 - SelectionSort
- 算法基础复习-SelectionSort
- 选择排序SelectionSort
- 【代码积累】SelectionSort
- bubblesort and selectionsort
- 选择排序(1)SelectionSort
- SelectionSort -- 选择排序(C++)
- GTK编程:获取屏幕分辨率
- android 颜色的色值
- C++基础系列(3)
- Unity3D研究院之游戏场景的切换与持久化简单数据的储存(十四)
- hihoCoder#1049 : 后序遍历
- Golang - SelectionSort
- 在Mac下重新设置mysql 的密码 出现 Access denied for user 'root'@'localhost'
- 新的实习开始了
- 2015年英语学习——3月
- [双系统]ubuntu下挂载Windows中wubi安装的ubuntu
- 探索应用开发的基础之android源文件的组织
- 61E Enemy is weak
- Can't create handler inside thread that has not called Looper.prepare()问题解决
- C++高质量编程学习笔记(3)