26 lines
510 B
Plaintext
26 lines
510 B
Plaintext
void QSort(void *base,U8 num, U8 width, I8 my_compare(void *e1,void *e2))
|
|
{ //This uses a shell sort
|
|
I8 span=num>>1,i;
|
|
U1 *b1,*b2,*temp=MAlloc(width);
|
|
BoolU4 cont;
|
|
|
|
while (span) {
|
|
cont=TRUE;
|
|
while (cont) {
|
|
cont=FALSE;
|
|
for (i=0;i+span<num;i++) {
|
|
b1=base+width*i;
|
|
b2=base+width*(i+span);
|
|
if (my_compare(b1,b2)>0) {
|
|
MemCpy(temp,b1,width);
|
|
MemCpy(b1,b2,width);
|
|
MemCpy(b2,temp,width);
|
|
cont=TRUE;
|
|
}
|
|
}
|
|
}
|
|
span>>=1;
|
|
}
|
|
Free(temp);
|
|
}
|