Link * merge(Link * A, Link * B) { Link * first = NULL, * last = NULL; while (A!=NULL && B!=NULL) { Link * wanted; if (A->data < B->data) { wanted = A; A = A->next; } else { wanted = B; B = B->next; } if (first == NULL) first = wanted; else last->next = wanted; last = wanted; last->next = NULL; } if (A != NULL) last->next = A; else if (B != NULL) last->next = B; return first; } |