我试图制作像qsort这样的东西但是当我尝试使用void*
void my_sort(void* base, size_t num, size_t size, int(*compare)(const void*, const void*))
{
size_t i, j;
const void *first, *second;
for (size_t i = 0; i < num*size; i+=size)
{
for (size_t j = size +i; j < num*size; j +=size)
{
first = base + i;
second = base + j;
if (compare(first,second)<0)
{
swap(base,i,j);
}
}
}
}
答案 0 :(得分:2)
first = ((char*) base) + i;
second = ((char*)base) + j;