Merge sort Linked list

what I am missing here?

Hello @Vikaspal,

Mistakes:

  1. Line 81 and line 88
  2. Line 97
  3. Line 109

Corrected Code:

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

1 Like

@S18ML0016

  1. line 97 . I can’t check like this if (head == NULL || head->next == NULL ) when i have the single node and also no node

Hello @Vikaspal,

Your problem is not clear. Please, give an example in support of your doubt.

@S18ML0016 you mentions that i missed the case when there is only single node i combine that both the case when there is no node head=null or when there is single node head->next == null . I want to put the conditions explicitly?

Hello @Vikaspal,

You can skip the case of head==NULL here, correcting myself.

Reason:
you will never reach this base case as you are returning for single node i.e. head->next==NULL.

Hope, it will help.

@S18ML0016 so it works fine for the both the even head is null first it will check it if i don’t write head == null it may happen head->next means null->next may create some issue ?

Hey @Vikaspal,

That is the catch, this will never happen.

Reason:
for array of size 3:
Division: one of size 1(return) and another of size 2.

for array of size 2:
Division: one of size 1(return) and another of size 1(return).

for array of size 1:
return

So, you’ll never reach the case of head == NULL.

Hope, it is clear now.

@S18ML0016 got it ur points

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.