Polynomal operator+ (Polynomal &A,Polynomal &B){ Term *pa,*pb,*pc,*p; float temp; Polynomal C; pc=C.first; pa=A.getHead()->link; pb=B.getHead()->link; while(pa!=NULL&&pb!=NULL){ if(pa->exp==pb->exp){ temp=pa->coef+pb->coef; if(fabs(temp)>0.001) pc=pc->InsertAfter(temp,pa->exp); pa=pa->link;pb=pb->link ; } else if(pa->expexp){ pc=pc->InsertAfter(pa->coef,pa->exp); pa=pa->link; } else{ pc=pc->InsertAfter(pb->coef,pb->exp); pb=pb->link; } } if(pa!=NULL) p=pa; else p=pb; while(p!=NULL){ pc=pc->InsertAfter(p->coef ,p->exp); p=p->link; } return C; }
http://blog.chinaunix.net/uid-25544300-id-317904.html