Implementazione in Linguaggio C dell’algoritmo BubbleSort su un vettore generico
#define TRUE 1
#define FALSE 0
typedef int (*compare_ptr)(void* V, int a, int b);
typedef void (*swap_ptr)(void* V, int a, int b);
void bubbleSort(void* V, int n, compare_ptr cmp, swap_ptr swp){
int flag = TRUE;
int i;
while(flag){
flag = FALSE;
for(i=0; i < n-1; i++){
if( cmp(V,i,i+1) ){
swp(V,i,i+1);
flag = TRUE;
}
}
}
}
Etichette: algoritmi di ordinamento, algoritmo, bubble sort, bubblesort, implementazione, linguaggio c