Name 3 15pt Suppose we are developing a library to deal with
Solution
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