1 void move(char *a ,char *b , int width )
2 {
3 if(a != b )
4 {
5 while( width--)
6 {
7 *a++ = *b++;
8 }
9 }
10 }
11 void insert_sort(void *array,int width , int num , int (*comp)(void *a,void *b) )
12 {
13 int i,j;
14 char *ptr;
15 char *mid = (char *)malloc( sizeof(char) * num * width );
16 ptr = (char *)array;
17
18 memset(mid,0,sizeof(mid));
19 for( i = 1 ; i < num ; i++ )
20 {
21 move(mid , ptr + i*width , width );
22 for(j = i ; j > 0 ; j-- )
23 {
24 if(comp( mid ,ptr + (j - 1)*width ) >= 0 )
25 {
26 break;
27 }
28 move( ptr + j*width , ptr + (j-1)*width ,width );
29 }
30 move(ptr + j * width , mid , width );
31 for( j = 0; j < num ; j++ )
32 printf("%d,",*( int*)(ptr + width*j));
33 }
34 }
35
36 int cmp(void *a,void *b )
37 {
38 int *aa ,*bb;
39 aa = (int *) a;
40 bb = (int *) b;
41 return *bb - *aa ;
42 }