im trying to write a function that takes two lists, each of which is sorted in increasing order, and merges the two together into one list which is in increasing order. Below is my function. Im not getting expected result. struct Node* MergeSortList(struct Node* head_ref_a, struct Node* head_ref_b) { struct Node newList; struct Node *tail = &newList; newList.next = NULL; if(head_ref_a == NULL) return head_ref_b; else if(head_ref_b == NULL) return head_ref_a; while(head_ref_a != NULL || head_ref_b != NULL) { if(head_ref_a->data data) { tail->next = head_ref_a; head_ref_a = head_ref_a->next; tail = tail->next; } else { tail->next = head_ref_b; head_ref_b = head_ref_b->next; tail = tail->next; } if (head_ref_a == NULL) { tail->next = head_ref_b; break; } else if (head_ref_b == NULL) { tail->next = head_ref_a; break; } } return newList.next; }
Didn't get the answer.
Contact people of Talent-Data Structure directly by clicking here