BucketSort

Implementazione in Linguaggio C dell’algoritmo BucketSort su una Lista.
La lista è implementata parzialmente (solamente le funzioni necessarie per l’esecuzione di questo sorgente).

int maxNode(queue_t* head){
int max = 0;
queue_t* dummy = head;
while(dummy!= NULL){
if(dummy->key > max )
max = dummy->key;
dummy = dummy->next;
}
return max;
}

queue_t* bucketSort(queue_t* head){
int n = maxNode(head) + 1;
if(n<=1)return head;
queue_t** V = (queue_t**)malloc(n*sizeof(head));
int i;

for(i=0; ikey;
dummy = head;
head = head->next;
V[i] = queue_enqueueOne(V[i],dummy);
}

head = NULL;

for(i=0; i<n; i++)
if(V[i] != NULL)
head = queue_enqueue(head,V[i]);

free(V);
return head;
}

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.