You are viewing a single comment's thread. Return to all comments →
So I basically tried to do the same thing but in C++ but I am getting a segmentation fault error. Any idea why?
Node* MergeLists(Node *headA, Node* headB) { if(headA == NULL){ return headB; } else if(headB = NULL){ return headA; } Node *head; if(headA->data < headB->data){ head = headA; headA = headA->next; } else{ head = headB; headB = headB->next; } Node *current = head; while(headA != NULL && headB != NULL){ if(headA->data < headB->data){ current->next = headA; headA = headA->next; } else{ current->next = headB; headB = headB->next; } current = current->next; } if (headA == NULL) { current->next = headB; } else { current->next = headA; } return head; }
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 →
So I basically tried to do the same thing but in C++ but I am getting a segmentation fault error. Any idea why?