BubbleSort

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: , , , , ,

Lascia un Commento

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Log Out / Modifica )

Foto Twitter

You are commenting using your Twitter account. Log Out / Modifica )

Foto di Facebook

You are commenting using your Facebook account. Log Out / Modifica )

Connecting to %s


Follow

Get every new post delivered to your Inbox.