Name: 3. (15pt) Suppose we are developing a library to deal with polynomials. To
ID: 3573898 • Letter: N
Question
Name: 3. (15pt) Suppose we are developing a library to deal with polynomials. To represent polynomials, we use single link lists with the following cell structure: type def struct pol 3x +2x 400 int coeffi int degree; coeff degree coeff degree o struct poly next polyT As in the above example, the terms of a polynomial are usually sorted in decreasing order of degrees But what if that is not the case (e.g., if the above polynomial was given as 3x3 400 +2x3), it would be represented as follows Suppose we want it to be sorted. So now you are asked to implement a function void poly sort (polyT p) which sorts the terms of a given polynomial in decreasing order of degrees as follows: use the next page to answer this question.Explanation / Answer
void sort(polyT *p)
{
polyT cur;
polyT *temp = head;
polyT *temp1;
while (temp != NULL)
{
temp1 = temp->next;
while (temp1 != NULL)
{
if (temp->degree < temp1->degree)
{
cur.coeff = temp->coeff;
cur.degree = temp->degree;
temp->coeff = temp1->coeff;
temp->degree = temp1->degree;
temp1->coeff = cur.coeff;
temp1->degree = cur.degree;
}
else
{
temp1 = temp1->next;
}
}
temp = temp->next;
}
}
---------------------------------------------------
when executed with full program , Output as below
output
Before sorting polynomial
Coefficient = 3 degree =5
Coefficient = -400 degree =0
Coefficient = 2 degree =3
After sorting polynomial
Coefficient = 3 degree =5
Coefficient = 2 degree =3
Coefficient = -400 degree =0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.