We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
these 4 lines took me a while to understand
Node* tmp= headB;
headB = headB->next;
temp->next = headA; the original headB now points to headA
headA = temp; headA now becomes original headB
It can be written as:
Node* tmp = headA;
headA = headB; // change the headA to headB
headA->next = MergeLists(tmp, headB->next); //tmp is the orginal headA
I hope people can usnstand it better with these 3 lines.
Cookie support is required to access HackerRank
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 →
these 4 lines took me a while to understand Node* tmp= headB; headB = headB->next; temp->next = headA; the original headB now points to headA headA = temp; headA now becomes original headB
It can be written as: Node* tmp = headA; headA = headB; // change the headA to headB headA->next = MergeLists(tmp, headB->next); //tmp is the orginal headA
I hope people can usnstand it better with these 3 lines.