Merge Sorted Linked Lists

My code is giving run-error.
But it works fine for the test cases I’ve given. Look into my code: https://ide.codingblocks.com/s/156604

Hi Rishav, you need to change your code a bit for example: - according to the input, so you have to make a function to build the linked list according to the desired input (a seprate function).

Here, I will break it down for you:-

  1. you have to find out the base case for the merge_sort
  2. divide the linked list into two parts.
  3. sort both linked list separately
  4. merge both linked list to make one list.

If you have any other doubts, please feel free to ask.

But I’m supposed to write merge function only, Two sorted linked lists are already given as input. What is the need of writing merge sort function?

Oh, Okay I misjudged your question.
You should update your input method.
But, in merge function also, you need to just compare the data and store it in a third node & other things will go using recursion.Then, return that node.

Try to implement this logic in code yourself.

Please feel free to ask again if you got trouble.

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.