Implement Polynom in C++ w/o Linked List

  • Context: Comp Sci 
  • Thread starter Thread starter erezb84
  • Start date Start date
  • Tags Tags
    C++
Click For Summary

Discussion Overview

The discussion centers on implementing polynomials in C++ without using linked lists, focusing on methods for addition and subtraction of polynomials. Participants explore data structures and ordering of terms for efficient manipulation.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests sorting polynomials by their exponents to facilitate addition, while questioning if sorting is necessary.
  • Another participant proposes using a simple array of doubles, with indices representing powers, as an alternative to linked lists.
  • Some participants clarify the requirement to use linked lists, with one suggesting to create a linked list where each node contains a term's coefficient and exponent, and to maintain order from lowest to highest exponent.
  • There is a discussion about the importance of preserving order in the polynomial representation to simplify operations like printing, comparing, and evaluating polynomials.
  • A participant mentions the potential utility of including zero terms or placeholders for future polynomial manipulations.

Areas of Agreement / Disagreement

Participants express differing views on the necessity of sorting polynomials for addition, and there is no consensus on the best data structure to use, with multiple competing approaches presented.

Contextual Notes

Participants discuss the implications of their chosen data structures and ordering methods, but the conversation does not resolve the effectiveness of these approaches or their limitations.

Who May Find This Useful

Individuals interested in data structures, polynomial manipulation, or C++ programming may find this discussion relevant.

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
Try using a simple array of double with the index being the power.
 
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
 
Ok,
Many Thanks!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K