my code gives wrong answer int all test cases but for given example it gives desired output. problem: merge two linked lists
Code gives wrong answer
Bhaiya mail krna h code
Follow these steps
- open ide.codingblocks.com
- paste your code
- click on the save
- copy the link and paste it here.
The problem is that if head1 or head2 becomes NULL you insert the next element of the one who hasnt become NULL, So for example if one linked list is 1,2 and the second linked list is 3, 4 your code would return 1, 2, 3.
So you need to replace the if with while
if(head1!=NULL) would change to while(head1!=NULL)
and
if(head2!=NULL) would change to while(head2!=NULL)
okk done .
thanks a lot
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.