# C++ implement polynom

1. Jan 23, 2012

### erezb84

Hi,
I need to implement polynoms in c++.
I thought of doing this with lined list,i am not alowed using c++ linked list, so i will built it myself.
I started thinking of adding and substructing,
should i first sort the polynoms i want to sum by its exponents? (in this case it will be easerear to compare between 2 exponents),
or is there a way doing the adding without sorting?...

Thanks!

2. Jan 23, 2012

### Staff: Mentor

Try using a simple array of double with the index being the power.

3. Jan 23, 2012

### erezb84

The instructions were to use a linked list...

4. Jan 23, 2012

### Staff: Mentor

Sorry I saw your comment that said you weren't allowed to use a linked list I took to mean you weren't allowed to write one either.

Okay so write one with content of the node containing the term factor and the power of the independent variable. Add nodes to the list in the order of the polynomial from x0 to xn.

5. Jan 23, 2012

### erezb84

In order to make the adding easier i need to save the polynom in this order right?
so if i need to add to a given polynom another node (with new coefficient and exponent) i nedd to insert it on the right place?

6. Jan 23, 2012

### Staff: Mentor

Yes by preserving the order you easily print or compare or evaluate a polynomial. If you want to add two polynomials together you'd create a new polynomial by merging the two.

You might also wan to put in zero terms as well as placeholders for future manipulation of the polynomial but that's not necessary. Zero term is like x0 + 0x1 + 3x2 ... For 3x^2 + 1

7. Jan 23, 2012

### erezb84

Ok,
Many Thanks!!