You are on page 1of 1

polynomial adding logic:

compare a node each node of first polynomial with every node of second polynomial(nested while or
for loop).. if powers x and y match make the flag variable as 1, insert it in the third polynomial by
adding both the coefficients(exception: if coefficients' sum up to ero don't insert)..
once all the the nodes of first polynomial is compared with all coefficients of second
polynomial(completion of while loops(nested)).. we have to add the terms(nodes) of which had not
matched. this is simple if flag variable is not 1 then insert it in third polynomial.. use loops for both
polynomials separately.. !ust read the example
eg: "x#$y#$% $x#&y#':: two nodes in one list % header.. first node coeff:$ pow of x : $ pow of y:$..
make all flag variables to ero.
second polynomial 'x#$y#$ % $x#1y#'..
we compare first node of first polynomial with all nodes of second polynomial till it matches
:
so comparing with first node , it matches.. insert ("%')x#$y#$ and move on to second node of
first polynomial(we assume that only one node in both the polynomial has same powers so skip
to second node and not compare it with further nodes.. use break statement in second nested loop).
(lag variables of both polynomial's nodes is made to one: p1)*flag + p')*flag + 1,

we compare next(second) node of first polynomial with all nodes of second polynomial till it matches
:
comparing with first node,powers do not match so move to second node of second polynomial..
still doesn't match so move to next node, but next node doesn't exist.. so while loop condition
fails..
we compare next(third) node but it doesn't exist..while loop condition fails.. both loops are done.
-ow we insert nodes with (flag .+ 1) so use a loop(i have used for loop since it's one line) for both the
polynomial in first one $x#&y#' is not flagged as one. /nd in second one $x#1y#' is not flagged.. so
insert both using separate for loops.

You might also like