#include <iostream>
using namespace std;
void SelectSort(int s[], int);
int main()
{
int a[10]={6,3,14,12,4,5,1,31,53,62,};
SelectSort(a,10);
cout<<endl;
cout<<"程序耗时: "<<clock()<<" ms"<<endl;
system("pause");
return 0;
}
void SelectSort(int s[], int len)
{
for(int x=0;x<len-1;x++)
cout<<"第 "<<x<<"趟选择排序的结果为: ";
for(int k=0;k<len;k++)
cout<<s[k]<<" ";
cout<<endl;
int min=x;
for(int i=x+1;i<len;i++)
if(s[i]<s[min]) {min=i;} ; //第二个for循环必须在此结束
if(min!=x)
{
int temp;
temp=s[min];
s[min]=s[x];
s[x]=temp;
}
}
}
简单选择排序
最新推荐文章于 2023-03-20 01:02:49 发布