Jan 25 C Jan 30 cl Feb 1 Clar (13) Find Lab4; Home-L +
file:///C:/Users/18254/Downloads/Lab4.pdf
Polynomial class
1/3
100% +
You are to implement a Polynomial class that supports an integer polynomial datatype. Quite
often, such a datatype can be implemented using a list or an array. However, our Polynomials
will be sparse, meaning that a lot of terms will be zero. In such a case, only the nonzero terms
should be stored in the data structure. For this assignment, you must use a linked list to store
the nonzero terms of the polynomial.
Your solution must adhere to the following specification:
1. Polynomials can be created with an optional list of tuples where a tuple represents a
(coefficient, exponent) pair.
For example, Polynomial(((1, 0), (3, 3), (2, 1)]) represents $3x^3 + 2x + 1$. Any combination
of tuples can be used to represent a polynomial. Exponents can appear more than once,
and coefficients can be zero. You must collect like terms and remove all terms that are
zero. Terms must be stored in descending order of exponent. Polynomials must be
stored in a unique or canonical form. Polynomial() with no argument creates a zero
polynomial $0x^0$.
2. The Polynomial class must implement a __str__() method that returns a string
representation of a Polynomial object so that it can be printed. A polynomial must be
printed in its stored canonical form, i.e., in descending order of exponent with no
terms or coefficients of 1. For the zero polynomial, this method should return "0
class Term:
def __init__(self, coefficient, exponent, next_term = None):
constructor
Purpose: To initalize the objects to a specific Int value
Paramter: coefficient - an Int value (can't be negative or zero),
exponent - an Int value (Can't be negative or zero)
pre: The user must in a valid value
Return: None
self.next_term = next_term
self.coefficient = coefficient
self.exponent = exponent
def __str__(self):
Return a user friendly string representation of this Int object
pass
class Polynomial:
def __init__(self, tuple_list = None):
self.head = None
Polynomial must be stored cannoncially