You are viewing a single comment's thread. Return to all comments →
Here is a simple recursive solution that passes both test cases!
if((headA==NULL)&&(headB==NULL) return NULL; if((headA!=NULL)&&(headB==NULL)) return headA; if((headA == NULL)&&(headB!=NULL)) return headB; if(headA->data < headB->data) headA->next = MergeLists(headA->next, headB); else if(headA->data > headB->data) { Node* temp = headB; headB = headB->next; temp->next = headA; headA = temp; headA->next = MergeLists(headA->next, headB); } return headA;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
Here is a simple recursive solution that passes both test cases!
}