下面是我昨天写的,思路已经被打乱啦,两个多项式输入输出没问题啦,这个相加函数实现不了
void add(){
lnode *s1,*head1,*head2,*s4,*s2=NULL;
head2=H2;
head1=H1;
int i=0;
for(int i=0;i<m;i++){
for(int w=0;w<n;w++){
if(H1->b=H2->b){
s1=new lnode;
if(!s1){cout<<"空间分配错误";exit(1);}
s1->a=H1->a+H2->a;
s1->b=H1->b;
i++;
if(H3==NULL)
H3=s1;
else
s2->next=s1;
s2=s1;
}
lnode *d;
d=H1;
H1=H1->next;
delete d;
d=H2;
H2=H2->next;
delete d;
H1=H1->next;
H2=H2->next;
}
if(H1->b!=H2->b){
H2=H2->next;
}
for(int k=1;k<=i;k++){
if(i>1&&H3->a>0)
cout<<"+"<<H3->a<<"x^"<<H3->b;
else
cout<<H3->a<<"x^"<<H3->b;
H3=H3->next;
}
}
}