Segmentation Fault
Hello @shubhamhalder0,
If you are writing this code for the challenges in your course
then your input format is very wrong.
- there are testcases.
- There should be two list to merge. You have read only one.
- The logic of building list will not work here.
Suggestion:
Please, read the question and all the formats given in the question properly.
Hope, this would help.
Give a like if you are satisfied.
This is merge sort code. It shows that there is segmentation fault.
My bad @shubhamhalder0,
I read the wrong question.
So, now coming back to your code:
The error is in the midpoint() function.
Correction:
// nodefast = head;
nodefast = head->next;
Reason:
As you have initialized both fast and slow with head,
So for a lined list of two elements, it will return slow as the second node of the list.
causing merge() function to stuck in an infinite loop as it will break the list into 2:0 ration for this returned value of mid.
Corrected Code:
Hope, this would help.
Give a like if you are satisfied.