1#include"stdio.h"2 intSearch_second_max (intArray[],intNintm)3 {4 intmax1;5 intI,num;6num=1;//Default First Name7 if(m>n)return 0; 8Max1 =Array[m];9 for(i =0; I < n; i++)Ten { One if(array[i]>max1) A { -num++; - } the - } - returnnum; - } + - + voidSortint*a,intL//A is an array address, L is an array length. A { at intI, J; - intv; - //Sort Body - for(i =0; I < L-1; i + +) - for(j = i+1; J < L; J + +) - { in if(A[i] > A[j])//as the front is larger than the back, then the exchange. - { tov =A[i]; +A[i] =A[j]; -A[J] =v; the } * } $ }Panax Notoginseng - //ranking the voidPaiming (int*a,int*b,int(CNintN) + { A intI, J; the intv; + intarrayindex[8][2]; - $ for(i=0;i<8; i++) $ { -arrayindex[i][0]=A[i]; -arrayindex[i][1]=i; the } - //sort body from small to largeWuyi for(i =0; I < N-1; i + +) the for(j = i+1; J < N; J + +) - { Wu if(arrayindex[i][0] > arrayindex[j][0])//as the front is larger than the back, then the exchange. - { Aboutv = arrayindex[i][0]; $arrayindex[i][0] = arrayindex[j][0]; -arrayindex[j][0] =v; - -v = arrayindex[i][1]; Aarrayindex[i][1] = arrayindex[j][1]; +arrayindex[j][1] =v; the - } $ } the the //ranking Times the for(i=0, j=1; i<n-1; i++) the { - in if(arrayindex[i][0]!=arrayindex[i+1][0]) the { theb[i]=J; AboutJ + +; theb[i+1]=J; the}Else the { +b[i]=J; -b[i+1]=J; the }Bayi } the the for(i=0; i<n;i++) - { -a[i]=arrayindex[i][0]; thec[i]=arrayindex[i][1]; the } the the } - the the intMainvoid) the {94 inta[8]={7,2,6,3,3,7,1,8}; the intnum; the inti; the intb[8];98 intc[8]; About -printf"---------------------------------------\ n");101 102Paiming (A,b,c,8); 103 for(i=0;i<8; i++)104 { theprintf"a[%d]=%d b[%d]=%d c[%d]=%d \ n", I,a[i],i,b[i],i,c[i]);106 } 107printf"\ n");108printf"----------------------------------------\ n");109 the 111 the 113}
Result output
---------------------------------------
A[0]=1 b[0]=1 c[0]=6
a[1]=2 b[1]=2 C[1]=1
A[2]=3 b[2]=3 c[2]=4
A[3]=3 b[3]=3 c[3]=3
A[4]=6 b[4]=4 c[4]=2
A[5]=7 b[5]=5 c[5]=5
A[6]=7 b[6]=5 c[6]=0
A[7]=8 b[7]=6 c[7]=7
----------------------------------------
--------------------------------
Process exited after 0.8098 seconds with return value 0
Please press any key to continue ...
C-language Implementation ranking algorithm and rank algorithm