Merge LInked List1

Its giving me runtime error. Please tell me why?
Also I would like to know what are the possible cases when runtime error ocurrs and how to deal with them.
link: https://ide.codingblocks.com/s/103928

Hello @vidyajaykushwaha,

Runtime error can occur due to following reasons:

  1. Invalid memory access during run-time.
  2. Accessing linked list nodes that do not exist.
  3. Dividing by zero.
  4. Large allocation of memory together/Large Static Memory Allocation.
  5. Making a silly mistake.

Now, coming back to your question:

There are two issues with merge_list function:

  1. You are using assignment operator instead of equality operator, which is causing wrong output
    else if(h1->data = h2->data)

2.The if-else statements after the while loop is causing run time error as you are pointing to the nodes of linked list instead of copying the data in the h3.

I have modified your code, now it’s running perfectly.
Click here to check.

Hope, this would help.
Give a like, if you are satisfied.

Another approach when size of list is known: https://online.codingblocks.com/player/25693/content/4687/4856

I cannot access that link.

Can you share the of online Coding Blocks IDE with your code saved there.

@vidyajaykushwaha, You have not replied to this thread for 5 days.

If your problem is solved, then mark this doubt as resolved.
Else, let me know, if you are still facing any issue.

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.