更新 '1.c'

This commit is contained in:
xtaodada 2022-03-06 04:51:50 -05:00
parent 5a229e4bf0
commit d7b258141f

28
1.c
View File

@ -253,20 +253,30 @@ void Delete(SING sing[MAX], int *num){
}
*num=*num-1;
}
void sort_xuhao(SING sing[MAX], int num){
void sort_xuhao(SING sing[MAX], int num, int n){
SING temp;
for(int i=0;i<num-1;i++){
for(int j=0;j<num-1-i;j++){
if(sing[j].num>sing[j+1].num){
// 交换
temp=sing[j];
sing[j]=sing[j+1];
sing[j+1]=temp;
if(n==1){
if(sing[j].num>sing[j+1].num){
// 交换
temp=sing[j];
sing[j]=sing[j+1];
sing[j+1]=temp;
}
}
else{
if(sing[j].num<sing[j+1].num){
// 交换
temp=sing[j];
sing[j]=sing[j+1];
sing[j+1]=temp;
}
}
}
}
}
void sort_aver(SING sing[MAX], int num){
void sort_aver(SING sing[MAX], int num, int n){
SING temp;
for(int i=0;i<num-1;i++){
for(int j=0;j<num-1-i;j++){
@ -293,10 +303,10 @@ void sort(SING sing[MAX], int num, int num_){
scanf("%d",&n);
switch(x){
case 1:
sort_xuhao(sing, num);
sort_xuhao(sing, num, n);
break;
case 2:
sort_aver(sing, num);
sort_aver(sing, num, n);
break;
default:
return;