Array

F

Febrizia

Scusate qualcuno conosce il codice esatto della funzione
x gli array dell'"insertion sort". Mi serve l'algoritmo completo scritto in
C.
Vi ringrazio molto x l'aiuto.
 
J

Jens.Toerring

Febrizia said:
Scusate qualcuno conosce il codice esatto della funzione
x gli array dell'"insertion sort". Mi serve l'algoritmo completo scritto in
C.
Vi ringrazio molto x l'aiuto.

Sorry, my Italian isn't good enough for an answer - and comp.lang.c
is in english anyway. Please understand that this isn't the right
place for asking for source code - if you have trouble writing it
show how far you got and people here will try to help you, but you
must have made at least some effort of your own. And you really
don't have to ask for an inplementation of insertion sort in C
since a google search for "insertion sort" will turn up several in
the very first hits.
Regards, Jens
 
P

pete

Febrizia said:
Scusate qualcuno conosce il codice esatto della funzione
x gli array dell'"insertion sort".
Mi serve l'algoritmo completo scritto in C.
Vi ringrazio molto x l'aiuto.

void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
unsigned char *array, *high, *low;
unsigned char swap, *p1, *p2, *end;

if (nmemb-- > 1) {
array = base;
do {
low = array;
high = array += size;
while (compar(low, high) > 0) {
p1 = low;
p2 = high;
end = p2 + size;
do {
swap = *p1;
*p1++ = *p2;
*p2++ = swap;
} while (p2 != end);
if (low == base) {
break;
}
high = low;
low -= size;
}
} while (--nmemb != 0);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,413
Latest member
KeiraLight

Latest Threads

Top