/*选择排序的思想,从第i个记录开始,
通过n-i次关键字比较,从n-i+1个关键
字中选出关键字较小的记录,并和第i个记录交换 */
#include<iostream>
using namespace std;
#define N 100
typedef int KeyType;
typedef char OtherType;
typedef struct RecordType{
KeyType key;
OtherType other_data;
}type;
void SelectSort(type a[],int n){
for(int i=1;i<n;i++){
int min=i;
for(int j=i+1;j<=n;j++)
if(a[j].key<a[min].key){
min=j;
}
if(min!=i){
type temp=a[i];
a[i]=a[min];
a[min]=temp;
}
}
}
int main(){
type a[N];
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].key;
SelectSort(a,n);
for(int i=1;i<=n;i++)
cout<<a[i].key<<" ";
return 0;
}
通过n-i次关键字比较,从n-i+1个关键
字中选出关键字较小的记录,并和第i个记录交换 */
#include<iostream>
using namespace std;
#define N 100
typedef int KeyType;
typedef char OtherType;
typedef struct RecordType{
KeyType key;
OtherType other_data;
}type;
void SelectSort(type a[],int n){
for(int i=1;i<n;i++){
int min=i;
for(int j=i+1;j<=n;j++)
if(a[j].key<a[min].key){
min=j;
}
if(min!=i){
type temp=a[i];
a[i]=a[min];
a[min]=temp;
}
}
}
int main(){
type a[N];
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].key;
SelectSort(a,n);
for(int i=1;i<=n;i++)
cout<<a[i].key<<" ";
return 0;
}