question–>
https://practice.geeksforgeeks.org/problems/sort-a-linked-list/1
code–>
Showing Segementation Fault!!!
MergeSort linkedlist
Hi @mr.encoder when i initialize
Node* f=head->next;(in line 2)
it is passing all Testcases ;
why is it happening like that?
Yeh code link open kro or mergesort function run kro, segmentation fault kha remove kiya hai tumhne?
bro share your that code which is getting all test case accepted
so that i can tell you why this is happening
here is the code which is passing all testcase
Now see this bro might be cause of weak test cases of gfg, whereas why this was working is cause
Node* mid1(Node* head){
Node* f=head->next;//here is the change
Node* s=head;
while(f!=NULL and f->next!=NULL){
f=f->next->next;
s=s->next;
}
return s;
}
This is the reason why 1 is getting missed in the linked list
okay it might be gfg weak test ,it works fine coding blocks ide
Have any other doubt bro?? If yes then do ask cause it’s a good question. Don’t leave any doubts in linked list topic cause as per me it’s one of the easiest Data structure.
If want to take reference from some code attaching the same here.
okay bro, for now there is no doubt for now
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.