QuickSort

By thedarketernalmike

Implementazione in Linguaggio C dell’algoritmo QuickSort su un vettore generico

typedef int(*compare_ptr)(void* V, int a, int b);
typedef void(*swap_ptr)(void* V, int a, int b);

int partition(void* V, int lo, int hi, compare_ptr cmp, swap_ptr swp){
int perno = lo;
int inf = lo + 1;
int sup = hi;

while(inf<=sup){
while( cmp(V,perno,inf) )inf++;

while( cmp(V,sup,perno) )sup--;

if(inf=hi)return;
int m = partition(V,lo,hi,cmp,swp);
quicksort(V,lo,m-1,cmp,swp);
quicksort(V,m+1,hi,cmp,swp);
return;
}

Tag: , , , , ,

Lascia un Commento

Occorre aver fatto il login per inviare un commento