简单选择排序是一种不稳定的排序算法,复杂度为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;
}
#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;
}