一元多项式加法函数的程序不知错哪里啦
这段程序编译时能通过,就是不能实现,运行时,直接跳过,求改错!void add(){
lnode *s1,*s2,*temp;
lnode *pre=NULL;
float sum;
s1=H1;
s2=H2;
pre=new lnode;
pre->next=H1;
while(s1!=NULL&&s2!=NULL){
if(s1->b<s2->b){
pre->next=s1;
pre=pre->next;
s1=s1->next;
}
else if(s1->b==s2->b){
sum=s1->a+s2->a;
if(sum==0){
temp=s1;
s1=s1->next;
delete temp;
temp=s2;
s2=s2->next;
delete temp;
}
else {
s1->a=sum;
pre->next=s1;
pre=pre->next;
s1=s1->next;
temp=s2;
s2=s2->next;
delete temp;
}
}
else{
pre->next=s2;
pre=pre->next;
s2=s2->next;
}
}
if(s1!=NULL)
pre->next=s1;
else
pre->next=s2;
cout<<"相加后的结果为:"<<endl;
s1=H1;
while(s1){
if(s1!=H1&&s1->a>0)
cout<<"+"<<s1->a<<"x^"<<s1->b;
else
cout<<s1->a<<"x^"<<s1->b;
s1=s1->next;
}
cout<<endl;
}