标签:info int ++ std ima esc lazy i++ sort
/* ????3ìDòμ?1|?üê?£oμ÷ó?Sort()??Dòoˉêy£?í¨1y′?μY?àó|2?êyó?????·¨°′éyDò£¨?ò?μDò£? ??êy×é?Dμ?êy??DD??Dò?£?ùéèêy×é?D′?′¢êy?Y?a{88,67,78,56,90}£?è?éyDò??Dò?ò?á1??a: {56,67,78,88,90}£?è??μDò??Dò?ò?á1??a {90,88,78,67,56}?£ */ #include <stdio.h> #include <stdlib.h> #define N 5 void Sort(int score[],int n,int (*compare)(int a,int b));//??Dòoˉêyéù?÷ int Ascending(int a,int b);//éyDò int Descending(int a,int b);//?μDò int main() { int i; int score[N]={88,67,78,56,90}; Sort(score,5,Ascending);//éyDò??Dò printf("The Ascending(éyDò) Sort is:"); for(i=0;i<5;i++) printf("%d ",score[i]); Sort(score,5,Descending);//?μDò??Dò printf("\nThe Descending(?μDò) Sort is:"); for(i=0;i<5;i++) printf("%d ",score[i]); return 0; } void Sort(int score[],int n,int(*compare)(int a,int b)) { int i,j,k; int t1,t2; for(i=0;i<n-1;i++){ k=i; for(j=i+1;j<n;j++){ if(compare(score[j],score[k])) k=j; } if(k!=i) { t1=score[k];score[k]=score[i];score[i]=t1; } } } int Ascending(int a,int b) { return a<b; } int Descending(int a,int b) { return a>b; }
运行结果:
标签:info int ++ std ima esc lazy i++ sort
原文地址:https://www.cnblogs.com/yanglike111/p/13716261.html