实验报告封皮
PNode *pa=ha->next,*pb=hb->next,*pc,*hc,*q;
int exp;
float coef;
hc=(PNode *)malloc(sizeof(PNode));
hc->exp=-1;
hc->next=hc;
pc=hc;
while (pa->exp!=-1 || pb->exp!=-1) {
if (pa->exp>pb->exp) {
exp=pa->exp;
coef=pa->coef;
pa=pa->next;
}
else if (pa->exp<pb->exp) {
exp=pb->exp;
coef=pb->coef;
pb=pb->next;
}
else {
exp=pa->exp;
coef=pa->coef+pb->coef;
pa=pa->next;
pb=pb->next;
}
if (coef!=0) {
q=(PNode *)malloc(sizeof(PNode));
q->exp=exp;
q->coef=coef;
q->next=pc->next;
pc->next=q;
pc=q;
}
}
return hc;
}
PNode * PolySubtract(PNode *ha,PNode *hb)
{
//编写此算法,实现两多项式(头指针分别为ha和hb)相减,返回差多项式hc=ha-hb。
PNode *hc=NULL;