You are viewing a single comment's thread. Return to all comments →
the C code
SinglyLinkedListNode* mergeLists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { if(head1==NULL)return head2; if(head2==NULL)return head1; SinglyLinkedListNode *mergedList; if(head1->data<head2->data) { mergedList = head1; head1=head1->next; } else { mergedList=head2; head2=head2->next; } SinglyLinkedListNode *current=mergedList; while(head2!=NULL && head1!=NULL) { if(head1->data<head2->data) { current->next=head1; head1=head1->next; } else { current->next=head2; head2=head2->next; } current=current->next; } if(head1!=NULL)current->next=head1; else current->next=head2; return mergedList; }
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 →
the C code