选择排序
来源:互联网 发布:詹姆斯数据排名 编辑:程序博客网 时间:2024/06/02 16:39
#include <iostream>using namespace std;void swap(int a[],int i,int min){ int temp = a[i]; a[i] = a[min]; a[min] = temp;}int main(int argc, char const *argv[]){ int a[] = {2,1,3,4,2,6,55,7}; int min = 0; for(int i = 0;i < sizeof(a)/sizeof(int);i++){ min = i; for(int j = i+1;j < sizeof(a)/sizeof(int);j++){ if(a[j] < a[min]) min = j; } swap(a,i,min); } for(int i = 0;i < sizeof(a)/sizeof(int);i++){ cout<<a[i]<<endl; } return 0;}
每一个数都会进行一次交换和N-1-i次比较
总共有N次交换和次比较
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序:
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 项目 2.2
- spring 的配置文件applicationContext.xml详解
- DOM中nodeName、nodeValue 及 nodeType的说明
- 坐标
- keil4中头文件路径设置的方法汇总
- 选择排序
- iOS中搜索条下来菜单怎么自动显示
- ZOJ题型分类
- Race Condition引起的性能问题
- undefined reference to `vtable for”
- Connect to a Windows Desktop from Ubuntu via Remote Desktop Connection
- [范例、标准]oracle执行标准(1)外键----已复制
- Objective-C入门
- javascript事件触发器