Printing the linked list

the value of the node pointer which we return from the function © is the address of the last node from the sorting of the two lists. we store this value in newhead and then print the new list. but new head should have the address of the first node to print the list? also we do not terminate the list by null in our new list?

hello @pranaynigam

we always return the updated head of the list.

last node of final list will eitheer be last node of first list or second list.
since both the nodes are already terminated by null ,there is no extra step need to terminate the final list with null

okay . but in print function we need first node to print the list (we transverse through the list to the last node and print the values while doing so), but we are getting the last node of either the first or the second list, then how are we printing the final list?

the merge function will return the address of first node of the resultant list only. so simply call ur print function on the returnd address

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.