Implement Polynom in C++ w/o Linked List

  • Context: Comp Sci 
  • Thread starter Thread starter erezb84
  • Start date Start date
  • Tags Tags
    C++
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 2K views
erezb84
Messages
43
Reaction score
0
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!
 
Physics news on Phys.org
The instructions were to use a linked list...
 
erezb84 said:
The instructions were to use a linked list...

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.
 
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?
 
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