using namespace std;
Struct poly real
{
Float coef.
Int expon;
Poly real * next;
};
Void createpoly (poly real * head)//create a list
{
Int a, n.
Poly real * s, * p;
P=the head;
Do
{
Cin> a> n;
If (a!
=10000){
S=new poly real;
S - & gt; Next=NULL;
S - & gt; Coef=a;
S - & gt; Expon=n;
P - & gt; Next=s;
P=s;
}
} while (a!=10000);
}
Void hebing (poly real * head)//merge similar terms, if the combined coefficient is zero, the removal of this node
{
Poly real * p * q * h, * j * I;
For (p=head - & gt; Next; P - & gt; Next!=NULL; P=p - & gt; Next)
{
For (q=p, h=p - & gt; Next; H!=NULL;)
{
If (h - & gt; Expon==p - & gt; Expon)
{
P - & gt; Coef +=h - & gt; Coef.
Q - & gt; Next=h - & gt; Next;
H=q - & gt; Next;
}
The else
{
H=h - & gt; Next;
Q=q - & gt; Next;
}
}
}
For (I=head, j=head - & gt; Next; J!=NULL;)
{
If (j - & gt; Coef==0)
{
I - & gt; Next=j - & gt; Next;
Delete (j);
J=I - & gt; Next;
}
The else
{
J=j - & gt; Next;
I=I - & gt; Next;
}
}
}
Void pailie (poly real * head)//in the polynomial all according to the size of the power, from big to small order
{
int i,j;
Poly real * p * q;
For (p=head - & gt; Next; P - & gt; Next!=NULL; P=p - & gt; Next)
{
I=p - & gt; Coef.
J=p - & gt; Expon;
For (q=p - & gt; Next; Q!=NULL; Q=q - & gt; Next)
{
If (q - & gt; Expon> J)
{
I=q - & gt; Coef.
J=q - & gt; Expon;
}
}
If (p - & gt; Expon!=j)
{
For (q=p - & gt; Next; Q - & gt; Expon!=j; Q=q - & gt; Next);
Q - & gt; Coef=p - & gt; Coef.
Q - & gt; Expon=p - & gt; Expon;
P - & gt; Coef=I;
P - & gt; Expon=j;
}
}
}
Void printpoly (poly real * head)//two polynomial addition
{
Int m=1, n=0;
Poly real * p;
Hebing (head);
Pailie (head);
For (p=head - & gt; Next; P!=NULL; P=p - & gt; Next)
N++;
Cout
{
Cout}
Cout
Poly real * addpoly (poly real * pa, pb) poly real *
{
Poly real * p, * s, * I * j;
I=pa;
J=pb;
S=pa - & gt; Next;
P=pb - & gt; Next;
While (s!=NULL& & P!=NULL)
{
If (I - & gt; Next - & gt; Expon==j - & gt; Next - & gt; Expon)
{
S - & gt; Coef +=p - & gt; Coef.
If (s - & gt; Coef!=0)
{
I=I - & gt; Next;
S=s - & gt; Next;
Delete (j);
J=new poly real;
P=p - & gt; Next;
J - & gt; Next=p;
}
The else
{
I - & gt; Next=s - & gt; Next;
The delete s;
S=I - & gt; Next;
The delete j;
J=new poly real;
P=p - & gt; Next;
J - & gt; Next=p;
}
}
Else if (I - & gt; Next - & gt; Expon
Delete (j);
J=new poly real;
J - & gt; Next=p - & gt; Next;
I - & gt; Next=p;
P - & gt; Next=s;
P=j - & gt; Next;
I=I - & gt; Next;
}
The else
{
I=I - & gt; Next;
S=s - & gt; Next;
}
}
If (p!=NULL)
{
Delete (j);
I - & gt; Next=p;
}
Return (pa);
}
Poly real * multiply (poly real * pa, pb) poly real *//in addition on the basis of implementation multiplication
{
Int k=0;
Poly real * STR [100], * p, * s * sum, * I * j;
I=pa - & gt; Next;
J=pb - & gt; Next;
for(i; i!=NULL; I=I - & gt; Next, k++)
{
STR [k]=new poly real;
STR [k] - & gt; Next=NULL;
P=STR [k].
J=pb - & gt; Next;
For (j; J!=NULL; J=j - & gt; Next)
{
S=new poly real;
S - & gt; Next=NULL;
S - & gt; Expon=I - & gt; Expon + j - & gt; Expon;
S - & gt; Coef=I - & gt; Coef * j - & gt; Coef.
P - & gt; Next=s;
P=s;
}
}
Sum=STR [0];
For (int m=1; M
Return (sum);
}
Int main ()
{
Poly3 poly2 poly1, poly real * *, * and * poly4, * head1, * p;
Head1=new poly real;
Head1 - & gt; Next=NULL;
P1=new poly real;
P1 - & gt; Next=NULL;
Cout<& lt;" Note: when the input polynomial "& lt;
Poly1=head1;
Cout<& lt;" You build a successful first polynomials, output the final expression is: "& lt;
Cout
Poly2=p;
Cout<& lt;" You set up the second polynomial b, output the final expression is: "& lt;
Cout
Cout<& lt;" You enter two polynomial multiplication, namely a * b result is: "& lt;
Cout