Implement a polynomial. A polynomial can be represent by its coefficients. Please implement the following functions. We assume that there will be at most 4096 terms in a polynomial. That is, the maximum power of a term is no more than 4095.
void init(Polynomial *poly, int coefficient, int n); Initialize a polynomial according to the coefficient[n-1] ... to coefficient, where coefficient[i] is the coefficient of $x$ to the power of $i$. It is guaranteed that the leading coefficient[n-1] is not 0.
Polynomial add(Polynomial *poly1, Polynomial *poly2); Add two polynomials and return the sum.
Polynomial multiply(Polynomial *poly1, Polynomial *poly2); Multiply two polynomials and return the product.
void print(Polynomial *poly); Print a polynomial, e.g., +3x^4+1x^2-2x-3. For simplicity we print all coefficient with its sign. We also assume that the polynomial will never be 0.
Do not print a term if the coefficient is 0, like the power of 3 above.
Do not print the power if it is 1 or 0, like the -2x and -3 above.
25pt. Implement init and print.
30pt. Implement init, add, and print.
35pt. Implement init, add, multiply, and print.
10pt. Implement init, add, multiply, and print efficiently.
In order to implement multiplication efficiently, you cannot treat the polynomial as if it has all 4096 terms. Instead you need to remember the number of terms in a polynomial, and process only these terms.
You can use "%+d" to force printf to print an integer with a '+' or a '-', depending on it is positive or negative.