how to make two intersected link list??for input it should be given so that we can make function for it??
Intersection of two link list
ya i did this i can do it …but interesection means address of one node of first list will be same with other list i want that node not value??so how to make this type of list??
@shampblocks
-Get count of the nodes in the first list, let count be c1.
-Get count of the nodes in the second list, let count be c2.
-Get the difference of counts d = abs(c1 – c2)
-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.
-Then we can traverse both the lists in parallel till we come across a common node. (Note that getting a common node is done by comparing the address of the nodes)
ya i understood that but my ques is how to make this type of common list??where one node is common by what criteria i will decie that i have to make common from this position???
@shampblocks
okay so you’re asking generally and not for the question, right.
if you want to make a list which is intersected
for example
first make the common part
list l = 8->4->2
then make the initial parts for both lists
list l1 = 4->1
and list l2 = 5->0->1
now do (tail of l1)->next = l;
also (tail of l2)->next = l;
This way you can make intersected lists.
so this think also should given in question that we have to make the list common from this node onwards??
@shampblocks
for the question, you don’t have to do anything like this, just make the two lists separately, actually the two lists will be created intersected, because there is one node where they intersect, there they have same value and same address, so make them separately.
ohk mam thanks…
…
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.
