Questo lo feci a suo tempo per interi... quindi basta che modifichi l'istruzione di confronto da int a stringacodice:struct linked * merge(struct linked *, struct linked *); struct linked *mergesort(struct linked *); struct linked * merge(struct linked *a, struct linked *b){ struct linked head; struct linked *node = &head; while((a != NULL) && (b != NULL)) if(a->value <= b->value){ node->next = a; node = a; a = a->next; } else{ node->next = b; node = b; b = b->next; } node->next = (a == NULL) ? b : a; return head.next; } struct linked *mergesort(struct linked *node){ struct linked *a = node; struct linked *b = node->next; if(node == NULL || node->next == NULL) return node; while((b != NULL) && (b->next != NULL)){ node = node->next; b = b->next; } b = node->next; node->next = NULL; return merge(mergesort(a), mergesort(b)); }
p.s. notare avatar per san valentino![]()
![]()


Rispondi quotando