#include
#include
# define NULL 0
Typedef struct Polynode {
Int coef.//factor
Int exp.//power
Struct Polynode * next;
} Polynode, * Polylist;
Polylist polycreate ()
{
Head rear Polynode * and * and * s;
Int c, e,
Rear=head=(Polynode *) malloc (sizeof (Polynode));
The scanf (" % d % d ", & amp; C., & amp; E);
While (c!=0)
{
S=(Polynode *) malloc (sizeof (Polynode));
S - & gt; Coef=c;
S - & gt; Exp=e;
Rear - & gt; Next=s;
Rear=s;
The scanf (" % d % d ", & amp; C., & amp; E);
}
Rear - & gt; Next=NULL;
Return (the head);
}
Polylist multyploy (Polylist Polylist pa, pb)
{
Polynode * t1, t2 * * t3, * t * rear, * p;
Int c, e,
T1=pa - & gt; next;
T2=pb - & gt; next;
P=(Polynode *) malloc (sizeof (Polynode));
P - & gt; Next=NULL;
Rear=p;
While (t2)
{
T3=(Polynode *) malloc (sizeof (Polynode));
T3 - & gt; Coef=t1 - & gt; Coef * t2 - & gt; Coef.
T3 - & gt; Exp=t1 - & gt; Exp + t2 - & gt; Exp.
T3 - & gt; Next=NULL;
Rear - & gt; Next=t3;
Rear=t3;
T2=t2 - & gt; next;
}
T1=t1 - & gt; next;
While (t1)
{
T2=pb - & gt; next;
Rear=p;
While (t2)
{
E=t1 - & gt; Exp + t2 - & gt; Exp.
C=t1 - & gt; Coef * t2 - & gt; Coef.
While (rear - & gt; Next& & Rear - & gt; Next - & gt; Exp
If (rear - & gt; Next& & Rear - & gt; Next - & gt; Exp==e)
{
If (rear - & gt; Next - & gt; Coef + c)
Rear - & gt; Next - & gt; Coef +=c;
The else
{
T=rear - & gt; next;
Rear - & gt; Next=t - & gt; next;
Free (t);
}
}
The else
{
T=(Polynode *) malloc (sizeof (Polynode));
T - & gt; Coef=c;
T - & gt; Exp=e;
T - & gt; Next=rear - & gt; next;
Rear - & gt; Next=t;
Rear=rear - & gt; next;
}
}
T1=t1 - & gt; next;
}
T2=p;
P=p - & gt; next;
Free (t2);
Return the p;
}
Void print (Polylist p)
{
P=p - & gt; next;
While (p)
{
Printf (" % d ", p - & gt; Coef);
Printf (" * x ^ % d ", p - & gt; Exp);
If (p - & gt; next!=NULL)
Printf (" + ");
P=p - & gt; next;
}
printf("\n");
}
Void main (int arg c, char * argv [])
{
Polylist pa, pb, PC;//define three said polynomial list
Pa=polycreate ();//create a pa list
Pb=polycreate ();//create the pb list
PC=multyploy (pa, pb);//do multiplication method, and the results stored in the PC list
Print (PC);//will be the result of the addition of a polynomial format shown in the output devices
}