Question: Write a C++ code for the following scenarios. The code should be complete in terms of its functionality. Suppose you are

Write a C++ code for the following scenarios. The code should be complete in terms of  its functionality.

    •    Suppose you are given 2 doubly-linked lists of the same length (equal number of nodes) containing integer data. You are required to implement the following function for the linked-lists.

mergeList (Node * , Node *) – Takes the header nodes of both the lists, merges them and returns the merged list in the following way.

    Identify the intersecting node between the lists (an intersecting node is the one that is present both lists. Note, it's not just the same data, but the address as well) and merge the lists in such a way that the list that whose sum of all the nodes before intersecting nodes is greater should be included in the resultant list at the start till the intersecting node and then the nodes from the other list should be included.


E.g.
10

15

20

35

Head A
50

75

15

Head B

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

1 Loop through both lists to find the intersecting node 2 Find the sum of element upto intersctin... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Physics Questions!