Intersection point in 2 linked lists

error?

hey @Vibhuti0206, before fetching both linked list to merge function you need make them of equal size.
I have corrected your code you can check it here https://ide.codingblocks.com/s/145290

what is the error in code?

hey @Vibhuti0206, you were traversing the both linked list of unequal size and there by accessing invalid address. You should traverese d distance of larger linked list so that after that both linked list becomes of eqaul size.

  1. Get count of the nodes in the first list, let count be c1.
  2. Get count of the nodes in the second list, let count be c2.
    3.Get the difference of counts d = abs(c1 – c2)
  3. Now traverse the bigger list from the first node till d nodes so that from here onwards both the lists have equal no of nodes.
  4. Then we can traverse both the lists in parallel till we come across a common node.
1 Like