https://ide.codingblocks.com/s/211581 what is wrong in my code why it is giving segenmrntatoion fault
Https://ide.codingblocks.com/s/211581 what is wrong in my code why it is giving segenmrntatoion fault
Segmentation fault is because your program is trying to read or write an illegal memory location.
This means that it is accessing some illegal memory like arr[-1] or something out of its size.
Dry run your code on some input and you will get to know about your mistake.
Here is your modified code. I highilghted the changes. Please check it out.
jump is an integer variable in your function insertatmiddle. So it can’t be equal to NULL. Try to correct it and tell me if you are able to do so.
i did not understand differnce between temp->next!=NULL and temp!=NULL
temp->next!=NULL means that temp should move forward in the linked list till temp’s next is not NULL.
In the linked list - 1 2 3, initially temp node is 1 and 1’s next is 2, so it moves forward. Now temp node is 2 and 2’s next is 3 so it moves forward. Now 3’s next is NULL as it is the last element of the linked list. So temp->next=NULL and the loop stops here. And we get the last node.
temp!=NULL moves one more step forward. So now temp=NULL after 3 and it breaks out of loop.
why we initialise jump=1 and len =0 . why we not initialise jump with 0 as same as we initial in length function
Dry run the code in both cases.
You will get to know about the mistake.