I am trying to iterate through two list objects representing polynomials to perform a multiplication operation. But I have been unable to fix the problem with the while loop because it never enters the nested for loops and size never gets decremented and I get an infinite loop. Can someone point me in the right direction? Thanks.
Code:
int size = b.PolyTerms.size();
while(!size < 0)
{
for(It = tmpPoly.PolyTerms.begin(); It != tmpPoly.PolyTerms.end(); ++It)
{
for(It2 = tmpPoly2.PolyTerms.begin(); It2 != tmpPoly2.PolyTerms.end(); ++It2)
{
exp = (*It) + (*It2);
size--;
++It;
++It2;
coeff = (*It) * (*It2);
tPoly.PolyTerms.push_back(exp);
tPoly.PolyTerms.push_back(coeff);
size--;
//reset It iterator to first term since there are still more terms to multiply
//in the second polynomial
It = tmpPoly.PolyTerms.begin();
}
}
}//end while
//Post-Condition: size < 0 so all of the terms in the second polynomial have
//been multiplied by the first term of the first polynomial. Repeat the
//process for the next term.
...