Here is my code:https://ide.codingblocks.com/s/221728
can you tell where in my code it is making segmentation fault
please point it out
Here is my code:https://ide.codingblocks.com/s/221728
can you tell where in my code it is making segmentation fault
please point it out
fixed it
ur while loop was an infinite loop
suppose temp1 runs to NULL it goes to head again
then eventually temp2 will run to NULL or temp1 wil again run to NULL at some point
see, this just fixes the runtime error
ur logic is however, faulty as well
because when the occurance of the node is not after equal no of nodes from the head in both the linked lists, temp1 and temp 2 will never be equal
the way to solve this is
count the number of nodes in the first list and second list
whichever is greater put it’s head pointer ahead by the number of nodes it has more
and then follow your logic
My logic is correct what I am doing is I am traversing both the list if one list becomes null I am putting it’s headB and if second head becomes null then point to headA by this way I can get the intersection node.
You correct my segmentation fault that’s all
here u go, using the logic that u implemented, i would still advise u to take a look at the more optimum logic
See what i did is trvaersed the first list if it reaches null then point it to head of the other list, so actually it will always meet in the second iteration because of the difference in the number of nodes, if you are not able to understand you correct my code according to what you are telling and then i will fix it according to my logic and share you the code
read my last code, i have fixed only the error in your code in that
It’s not passing the testcases please post correct code
Can you post your correct or you are slept
because i told u to use a different logic, in a lot of cases, the complexity is very high
consider a case when the difference in heights is huge both will be traversing in the same list for a long time and each time just going ahead by a very few steps