更新 '1.c'

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

18
1.c
View File

@ -253,10 +253,11 @@ void Delete(SING sing[MAX], int *num){
} }
*num=*num-1; *num=*num-1;
} }
void sort_xuhao(SING sing[MAX], int num){ void sort_xuhao(SING sing[MAX], int num, int n){
SING temp; SING temp;
for(int i=0;i<num-1;i++){ for(int i=0;i<num-1;i++){
for(int j=0;j<num-1-i;j++){ for(int j=0;j<num-1-i;j++){
if(n==1){
if(sing[j].num>sing[j+1].num){ if(sing[j].num>sing[j+1].num){
// 交换 // 交换
temp=sing[j]; temp=sing[j];
@ -264,9 +265,18 @@ void sort_xuhao(SING sing[MAX], int num){
sing[j+1]=temp; 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; SING temp;
for(int i=0;i<num-1;i++){ for(int i=0;i<num-1;i++){
for(int j=0;j<num-1-i;j++){ 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); scanf("%d",&n);
switch(x){ switch(x){
case 1: case 1:
sort_xuhao(sing, num); sort_xuhao(sing, num, n);
break; break;
case 2: case 2:
sort_aver(sing, num); sort_aver(sing, num, n);
break; break;
default: default:
return; return;