C++ 简单选择排序

来源:互联网 发布:sql分组累计求和 编辑:程序博客网 时间:2024/05/29 13:55
简单选择排序是一种不稳定的排序算法,复杂度为n^2
#include
using namespace std;
void s_selsort(int a[],int n)
{
    int temp,temp2;
for(int i=0;i
{
    temp=i;
    for(int j=i+1;j
     if(a[temp]>a[j])
       temp=j;
     temp2=a[i];
     a[i]=a[temp];
     a[temp]=temp2;
}
 
}
int main()
{
    int a[]={2,6,3,4,9,5,3,2,1,9,3};
    s_selsort(a,11);
    for(int i=0;i<11;i++)
        cout<<a[i]<<",";
return 0;
}
0 0
原创粉丝点击