- #include <stdio.h>
- typedef struct
- { int key;
- /* float info;*/
- }JD;
- void binsort(JD r[],int n)
- { int i,j,x,s,m,k;
- for(i=2;i<=n;i++)
- { r[0]=r[i];
- x=r[i].key;
- s=1; j=i-1;
- while(s<=j)
- { m=(s+j)/2;
- if(x<r[m].key) j=m-1;
- else s=m+1;
- }
- for(k=i-1;k>=s;k--)
- r[k+1]=r[k];
- r[s]=r[0];
- }
- }
- void main()
- {
- static JD r[]={0,30,13,70,85,39,42,6,20};
- int i,n=8;
- binsort(r,n);
- for(i=1;i<=n;i++)
- printf("%d ",r[i].key);
- printf("n");
- }