[C] 纯文本查看 复制代码mulpoly *poly_add(mulpoly *a,mulpoly *b) // 两个多项式求和函数
{//************************************************
mulpoly *p,*q;
int s;
double sum;
a=a->next;
b=b->next;
q=p=new node;
if(!p)
return NULL;
p->next=NULL;
cout <
while(a!=NULL && b!=NULL)
{
if(a->exp > b->exp)
{
q->next=new node;
q=q->next;
q->coef=a->coef;
q->exp=a->exp;
q->next=NULL;
a=a->next;
}
if(a->exp < b->exp)
{
q->next=new node;
q=q->next;
q->coef=b->coef;
q->exp=b->exp;
q->next=NULL;
b=b->next;
}
if(a->exp == b->exp)
{
sum=a->coef+b->coef;
s=(int)sum;
if(s)
{
q->next=new node;
q=q->next;
q->coef=sum;
q->exp=a->exp;
q->next=NULL;
a=a->next;
b=b->next;
}
}
}
while(a)
{
q->next=new node;
q=q->next;
q->coef=a->coef;
q->exp=a->exp;
q->next=NULL;
a=a->next;
}
while(b)
{
q->next=new node;
q=q->next;
q->coef=b->coef;
q->exp=b->exp;
q->next=NULL;
b=b->next;
}
return p;
//================================================
}