int cmp(const void* a, const void* b){it would easily cause a overflow, like 2000000000-(-2000000000), it would overflow and become a negative number.
return *(int*)a - *(int*)b;
}
instead, we should use a compare function like
int cmp(const void* a, const void* b){
if(*(int*)a > *(int*)b)return 1;
else if(*(int*)a < *(int*)b)return -1;
return 0;
}
沒有留言:
張貼留言