从当前未排序的整数中找到最小的整数,将它放在已排序的整数列表的最后。
#include<iostream>
#include<Windows.h>
#include<time.h>
using namespace std;
void SelectSort(int *List, const int n);
int main()
{
clock_t start_time = clock();
int x[] = { 1,3,5,7,9,0,2,4,6,8 };
SelectSort(x, 10);
for (int k = 0; k < 10; k++)
cout << x[k] << endl;
clock_t end_time = clock();
cout << \"程序段运行时间:\" << static_cast<double> (end_time - start_time) / CLOCKS_PER_SEC * 1000 << \"ms\" << endl;
system(\"pause\");
return 0;
}
void SelectSort(int *List, const int n)
{
for (int i = 0; i < n-1; i++)
{
int min = i;//min处,假设第一个是最小的,是;数组的下标
for (int j = i + 1; j < n; j++) //j=i+1是因为之前已经扫描过了
{
if (List[j] < List[min])
{
min = j; //移动记录下来
}
}
swap(List[i], List[min]); //扫描一遍结束后,交换一次
}
}
继续阅读与本文标签相同的文章
下一篇 :
26-Python文件操作
-
四方科技:冷链装备龙头 罐箱业务全球领先
2026-05-19栏目: 教程
-
一眼望去 都是中国好CP的形状
2026-05-19栏目: 教程
-
前端开发深水区讨论
2026-05-19栏目: 教程
-
精读《使用 css 变量生成颜色主题》
2026-05-19栏目: 教程
-
震撼!全球首台“智慧旅游黑科技车”现身井陉……
2026-05-19栏目: 教程
