SEGMENTATION FAULT
MERGE SORT ON LINKED LIST
SEGMENTATION FAULT
MERGE SORT ON LINKED LIST
Add this in insertathead
if(head==NULL){
head=new node(d);
return ;
}
Correction in mid_point function: while(fast!=NULL&&fast->next!=NULL)
because if fast is null then fast ->next gives error so order should be swapped
Also remove cout statement in it
Correction in main:
cout<<mergesort(head);
you havent overloaded << so cant do like this
After doing these changes try to debug the remaining code yourself first.
I didn’t use insertAthead function. Do you mean correction in insertAtend() ?
Okay now it works well for small number of inputs. But if i try to give input from 1-100 it returns 50 and 100 only. Why so ? https://ide.codingblocks.com/s/325166
Hey add head=c;
after line 85 & before returning c so that the changes we have done reflect back
Okaayy thank you. But how come the code was working perfectly for small number of inputs without adding head=c ?
For which case it was working before ?
It will work perfectly for n<=3 without this line as well
No it is working correctly for 20 or 30 inputs as well
Without that line
For this input
10
1 2 4 1 4 1 4 1 4 1
I am getting
1 1 2 4 4 4 4 i.e 7 values
So maybe it was looking right but not actually right.
Now if your doubt is resolved then please mark it so