数据结构一元多项式计算 第4页
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp=p->exp;
=s;
r=s;
p=p->next;
}
}
while(p!=NULL)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp=p->exp;
r->next=s;
r=s;
p=p->next;
}
while(q!=NULL)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=q->coef;
s->exp=q->exp;
r->next=s;
r=s;
q=q->next;
}
r->next=NULL;
headc=headc->next;
return headc;
}
pnode * sub(pnode *heada,pnode *headb)
{
pnode *headc,*p,*q,*s,*r;
float x;
p=heada;q=headb;
headc=(pnode *)malloc(sizeof(pnode));
r=headc;
while(p!=NULL&&q!=NULL)
{if(p->exp==q->exp)
{x=p->coef-q->coef;
if(x!=0)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=x;
s->exp=p->exp;
r->next=s;
r=s;
}
q=q->next;p=p->next;
}
else if(p->exp<q->exp)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=-q->coef;
s->exp=q->exp;
r->next=s;
r=s;
q=q->next;
}
else
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp
r->next=s;
r=s;
p=p->next;
}
}
while(p!=NULL)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp=p->exp;
r->next=s;
r=s;
p=p->next;
}
r->next=s;
r=s;
q=q->next;
}
r->next=NULL;
headc=headc->next;
return headc;
}
void add_main()
{pnode * a,*b,*c;
printf("input the first:\n");
a=creat();
tiao_zheng(a);
printf("input the second:\n");
b=creat();
tiao_zheng(b);
c=add(a,b);
printf("the first:");display(a);
printf("the second:");display(b);
printf("sum is:");display(c);
}
void sub_main()
{pnode * a,*b,*c;
printf("input the first:\n");
a=creat();
tiao_zheng(a);
printf("sub is:");display(c);
}
void open()
{
printf("******************************\n");
printf(" 一元多项式计算器\n");
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页