您的位置:首页 > Web前端

(算法设计技巧与分析)SelectionSortFec

2015-03-10 00:29 417 查看


#include<iostream>
#include<time.h>
using namespace std;
void SelectionSortFec(int a[],int i,int n);
int main()
{
int a[11];
srand((unsigned int(time(NULL))));//导入时间种子加每次运行结样试下伪随机数种子
for (int i=0;i<11;i++)
a[i]=rand();
SelectionSortFec(a,0,11);
for(int i=0;i<11;i++)
cout<<a[i]<<endl;
return 0;
}
void SelectionSortFec(int a[],int i,int n)
{
if(i<n)
{
int temp=i,j=i+1;
while(j<n)
if(a[temp]<a[j++])
temp=j-1;
if(temp!=i)
{
j=a[i];
a[i]=a[temp];
a[temp]=j;
}
SelectionSortFec(a,i+1,n);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: