主题:承上
polypointer jia(polypointer a,polypointer b)
{
polypointer p,q,d,c;
int x;
p=a->link;
q=b->link;
c=new polynode;
d=c;
while((p!=NULL)&&(q!=NULL))
switch(compare(p->exp,q->exp))
{
case'=':
x=p->coef+q->coef;
if(x)
d=attach(x,p->exp,d);
p=p->link;
q=q->link;
break;
case'>':
d=attach(p->coef,p->exp,d);
p=p->link;
break;
case '<':
d=attach(q->coef,q->exp,d);
q=q->link;
break;
}
while(p!=NULL)
{
d=attach(p->coef,p->exp,d);
p=p->link;
}
while(q!=NULL)
{
d=attach(q->coef,q->exp,d);
q=q->link;
}
d->link=NULL;
p=c;
c=c->link;
delete p;
return c;
}
polypointer jian(polypointer a,polypointer b)
{
polypointer p,q,d,c;
int x;
p=a->link;
q=b->link;
c=new polynode;
d=c;
while((p!=NULL)&&(q!=NULL))
switch(compare(p->exp,q->exp))
{
case'=':
x=p->coef-q->coef;
if(x)
d=attach(x,p->exp,d);
p=p->link;
q=q->link;
break;
case'>':
d=attach(p->coef,p->exp,d);
p=p->link;
break;
case '<':
d=attach((0-q->coef),(0-q->exp),d);
q=q->link;
break;
}
while(p!=NULL)
{
d=attach(p->coef,p->exp,d);
p=p->link;
}
while(q!=NULL)
{
d=attach((0-q->coef),(0-q->exp),d);
q=q->link;
}
d->link=NULL;
p=c;
c=c->link;
delete p;
return c;
}
{
polypointer p,q,d,c;
int x;
p=a->link;
q=b->link;
c=new polynode;
d=c;
while((p!=NULL)&&(q!=NULL))
switch(compare(p->exp,q->exp))
{
case'=':
x=p->coef+q->coef;
if(x)
d=attach(x,p->exp,d);
p=p->link;
q=q->link;
break;
case'>':
d=attach(p->coef,p->exp,d);
p=p->link;
break;
case '<':
d=attach(q->coef,q->exp,d);
q=q->link;
break;
}
while(p!=NULL)
{
d=attach(p->coef,p->exp,d);
p=p->link;
}
while(q!=NULL)
{
d=attach(q->coef,q->exp,d);
q=q->link;
}
d->link=NULL;
p=c;
c=c->link;
delete p;
return c;
}
polypointer jian(polypointer a,polypointer b)
{
polypointer p,q,d,c;
int x;
p=a->link;
q=b->link;
c=new polynode;
d=c;
while((p!=NULL)&&(q!=NULL))
switch(compare(p->exp,q->exp))
{
case'=':
x=p->coef-q->coef;
if(x)
d=attach(x,p->exp,d);
p=p->link;
q=q->link;
break;
case'>':
d=attach(p->coef,p->exp,d);
p=p->link;
break;
case '<':
d=attach((0-q->coef),(0-q->exp),d);
q=q->link;
break;
}
while(p!=NULL)
{
d=attach(p->coef,p->exp,d);
p=p->link;
}
while(q!=NULL)
{
d=attach((0-q->coef),(0-q->exp),d);
q=q->link;
}
d->link=NULL;
p=c;
c=c->link;
delete p;
return c;
}