#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void selSort(double arrayTest[],int len){
double temp = 0.0;
int min = 0;
for(int i = 0;i<len-1;i++){
min = i;
for(int j =i+1;j<len; j++){
if(arrayTest[min] > arrayTest[j]){
min = j;
}
cout<<min<<"\t";
}
cout<<endl;
temp = arrayTest[i];
arrayTest[i] = arrayTest[min];
arrayTest[min] = temp;
}
}
void display(double arr[],int len){
for(int i = 0; i < len; i++){
cout<<arr[i]<<"\t";
}
}
int main() {
int len = 10;
double arrayTest[len] = {-2,15,65,2,34,87,99,45,66,20};
selSort(arrayTest,len);
display(arrayTest,len);
return 0;
}
复试3.2选择排序c++
最新推荐文章于 2021-11-14 19:09:47 发布