You are viewing a single comment's thread. Return to all comments →
C++
SinglyLinkedListNode* mergeLists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { if (head2 == nullptr) { return head1; } if (head1 == nullptr) { return head2; } SinglyLinkedListNode* result; if (head1->data <= head2->data) { result = head1; result->next = mergeLists(head1->next, head2); } else { result = head2; result->next = mergeLists(head1, head2->next); } return result; }
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 →
C++