answersLogoWhite

0


Best Answer

Linked lists are a good way to represent polynomials. The coefficients of each term would be a node in the linked list, with the first node representing X0 and each successive node representing the next higher power of X; X1, X2, etc..

To add two polynomials, you simply add the coefficients of like terms. To add linked lists, you simply add the values of like orders, i.e. you would add the first nodes together, the second terms together, the third terms together, and so on and so forth.

You iterate through both polynomials (linked lists) and add the coefficients. You either generate a third linked list or you add the first to the second, as desired. You need to be able to handle list extension, and when you run out of terms on one list, you stop.

In C or C++ (or other language supporting self referential structures) you can implement this simply by building a linked list and providing functions to iterate and add. If you have an OO language like C++ or JAVA, you can actually implement a class, creating a new type, polynomial, so that the interface could be as simple as...

polynomial a (1, 2, 3, 4, 5);

polynomial b (2, 4, 6, 0, 8, 10, 12);

a = a+b;

// the result would be a (3, 6, 9, 4, 13, 10, 12)

Actual implementation is not shown, because that is a large effort, because the question only asked "how", and because we are not really here to do your homework.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you Add two polynomial using a link list in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp