Selection sort 选择排序
来源:互联网 发布:无人机淘宝可靠吗 编辑:程序博客网 时间:2024/05/01 13:38
维基百科选择排序:https://en.wikipedia.org/wiki/Selection_sort
在一个无序的序列中选择最小(最大)的数置换到这个数列的一边,然在再在剩下的无序的数列中选择最小(最大)的数再置换到有序的这一边,就这样一一的把无序的数按大小置换到有序的这边,直到序列置换结束。
排序示意图:
代码:
#include <stdio.h>void selection_sort(int n[], int len){int i, j, min, temp;for (i=0; i < len; i++) {min = i;for (j = i; j < len; j++) {if (n[j] < n[min]) {min = j;}}if (min != i) {temp = n[i];n[i] = n[min];n[min] = temp;}}}int main(){int number[] = {8, 5, 2, 6, 9, 3, 1, 4, 0, 7};int len;int i;len = sizeof(number)/sizeof(number[0]);selection_sort(number, len);printf("\n");for (i=0; i < len; i++) {printf("%d ", number[i]);}printf("\n");return 0;}
0 0
- 选择排序(selection sort)
- 选择排序(Selection Sort)
- selection sort 选择排序
- 选择排序 Selection Sort
- 选择排序(Selection Sort)
- 选择排序(Selection Sort)
- 选择排序 (Selection Sort)
- 选择排序(Selection sort)
- 选择排序 (Selection sort)
- 选择排序Selection sort
- Selection Sort(选择排序)
- 选择排序(Selection Sort)
- Selection Sort选择排序
- selection sort 选择排序
- selection sort(选择排序)
- Selection sort 选择排序
- 选择排序Selection sort
- 选择排序(Selection Sort)
- spring配置详解
- 剑指offer 牛客网 。。。
- HTTP协议
- go 解析XML 设置缺省att的默认值
- [转发][纯记录]raid组的初始化详解
- Selection sort 选择排序
- PHP调试网页出现乱码解决方法!
- OpenCV视频进度播放控制
- opengl学习笔记(2)
- pl_sql
- 得到view的信息以及 view绘制流程解析
- JAVA高并发学习笔记(四) 无锁
- check tech
- 高效编程