/* Your function will be put here */
Polynomial Add( Polynomial a, Polynomial b )
{
if(!a->Next)return b;
if(!b->Next)return a;
Polynomial head = malloc(sizeof(Polynomial));
Polynomial p = head->Next;
a = a->Next;
b = b->Next;
while(a&&b)
{
Polynomial pc = malloc(sizeof(Polynomial));
if(a->Exponent==b->Exponent)
{
pc->Coefficient = a->Coefficient + b->Coefficient;
if(!pc->Coefficient)
{
a=a->Next;
b=b->Next;
continue;
}
pc->Exponent = a->Exponent;
pc->Next = NULL;
p->Next = pc;
p = pc;
a=a->Next;
b=b->Next;
}
else
{
if(a->Exponent > b->Exponent)
{
pc->Coefficient = a->Coefficient;
pc->Exponent = a->Exponent;
pc->Next &#
6-10 Add Two Polynomials (20 分)-数据结构第2章
最新推荐文章于 2022-01-12 14:33:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)