+2 votes
in Mathematics by kratos

Write an algorithm to add two polynomials using linked list.

1 Answer

+6 votes
by kratos
 
Best answer

Algorithm to add two polynomials using linked liLet p and q be the Let p and q be the two polynomials represented by linked lists

  1. while p and q are not null, repeat step 2.

  2. If powers of the two terms ate equal

then if the terms do not cancel

then insert the sum of the terms into the sum Polynomial

Advance p

Advance q

Else if the power of the first polynomial> power of second

Then insert the term from first polynomial into sum polynomial

Advance p

Else insert the term from second polynomial into sum polynomial

Advance q

  1. copy the remaining terms from the non empty polynomial into the sum polynomial.

The third step of the algorithm is to be processed till the end of the polynomials has not been reached.

...