标签:严格 下标 mes str class 最小值 style sort select
1 //选择排序的时间复杂度为O(n平方),略优于冒泡排序 ,严格的n方,与数据状态无关 2 #include<iostream> 3 using namespace std; 4 void Selectsort(int a[],int n) 5 { 6 int temp; 7 for(int i=0;i<n-1;i++)//n-1次循环,每一次循环确定下标为i的值是多少 8 { 9 int p=i;//p记录当前循环的最小值的下标 10 for(int j=i;j<n;j++) 11 { 12 if(a[j]<a[p]) p=j; 13 } 14 if(p!=i) 15 { 16 temp=a[i]; 17 a[i]=a[p]; 18 a[p]=temp; 19 } 20 } 21 } 22 int main() 23 { 24 int a[10]; 25 for(int i=0;i<10;i++) 26 { 27 cin>>a[i]; 28 } 29 Selectsort(a,10); 30 for(int i=0;i<10;i++) 31 cout<<a[i]<<endl; 32 }
标签:严格 下标 mes str class 最小值 style sort select
原文地址:https://www.cnblogs.com/TYXmax/p/10985945.html