简单选择排序
2015-10-18 13:02
337 查看
选择排序(Selection Sort)的基本思想:对n个记录进行扫描,选择最小的记录,将其输出,接着在剩下的n-1个记录中扫描,选择最小的记录将其输出,……不断重复这个过程,直到只剩一个记录为止。
# include <iostream> using namespace std; //升序 void SimpleSort(int *a,int n); int main(){ int a[]={1,65,89,-5,6,-569}; SimpleSort(a,6); for(int i=0;i<6;i++){ cout<<a[i]<<" "; } cout<<endl; return 0; } void SimpleSort(int *a,int n){ int i,j,k,t; for(i=0;i<n-1;i++){ k = i; for(j=i+1;j<n;j++) if(a[j]<a[k]) k = j; t = a[i]; a[i] = a[k]; a[k] = t; } }
相关文章推荐
- (Android+IOS)我们正在做一个新闻App,做几乎一样的,倾听您的建议 (画画)
- grbl
- Java IO3:字节流
- java中this用法 super()用法 以及构造方法
- 计算机基本知识拾遗(七)页面缓存数据的同步和恢复机制页
- 汉诺塔的相关应用
- java-encodeURI decodeURI
- 自定义单元格,使用TableViewCell的方式
- 计算机网络 2. 应用层
- Cup(二分)
- ubuntu终端常用的快捷键
- poj 1573 Robot Motion
- LintCode "Maximum Subarray Difference"
- 错误代码: 1366 Incorrect integer value: 'zhangsan' for column 'depart_teacher' at row 1
- Spring整合Cache
- Java连接Oracle数据库存储过程(用户财产变更举例)
- 编译,运行
- Python 基础
- Attack(树状数组)
- union的特性,去重与不去重