使用选择法进行排序,代码:
#includeusing namespace std;struct Students { int num; char name[20]; char sex; int score; };int main(){ struct Students su[5] ={ {1001,"xway",'M',93},{1002,"minve",'F',49},{1003,"glove",'F',43}, {1004,"sk",'M',65},{1005,"fys",'M',86} }; struct Students temp; const int n=5; int i,j,k; cout<<"before sort:"< su[k].score)//遍历并找到此次的最大值 k=i;//mark下标 temp=su[k];su[k]=su[i];su[i]=temp;//交换,吧=把此次的最大值放到当前位置 } for(i=0;i
运行结果