Loop not working in Polynomial Class

I have a polynomial class. This function adds two polynomials together by inserting the terms of the second polynomial into the first one. If the second polynomial has one term it works, but if it has more than one term, the loop only captures the last term and adds it, and I don't know why.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void Polynomial::add(Polynomial b)
{
    //if b is empty, original polynomial is itself

    if (!b.isEmpty())
    {
        int bTemp = b.head;

        while (bTemp != -1)
        {
            insertTerm(b.array[bTemp].coefficient,
                       b.array[bTemp].exponent);
            bTemp = b.array[bTemp].next;
        }

        simplify();
    }
}


Simplified from: http://www.cplusplus.com/forum/general/81750/
Topic archived. No new replies allowed.