Help needed
I was writing a sorting function the way qsort was on some old compilers. I does a selection sort. For some strange reason, it does not work.
v is a pointer to the vector to be sorted.
nv is the number of elements to be sorted
dimel is the dimension of one element
Fc is the function that compares two elements
TFComp2 is defined as:
typedef int (* TFComp2)(const void *, const void *);
int Sortare(void *v, size_t nv, size_t dimel, TFComp2 Fc)
{
char* i=CP(v);
char* isel,* count;
char* n=nv*dimel+i;
char* buffer = CP(malloc(dimel));
if (buffer==NULL)
return 0;
while(ii)
{
memcpy(buffer, isel, dimel);
memcpy(isel, i, dimel);
memcpy(i, buffer, dimel);
}
i+=dimel;
}
return 0;
}
Could someone please explain me WHY it does not work? I''m kindof under pressure here, so help is appreciated.
Saru
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement