/**
Polynominal& Polynominal::operator +(Polynominal& poly)
iter1=this.pList.begin
iter2=poly.pList.begin
while(iter1!=pList.end && iter2!=poly.pList.end)//比较,选择小的挂上po.pList
if(iter1->exp < iter2->exp)
po->pList.push(*iter1++)
if(iter1->exp > iter2->exp)
po->pList.push(*iter2++)
if(iter1->exp == iter2->exp)
po->pList.push(*iter1+*iter2)
while(iter1!=pList.end())//如果有剩余,则挂上po.pList
po->pList.push_back(*iter1++);
while(iter2!=poly.pList.end())//如果有剩余,则挂上po.pList
po->pList.push_back(*iter2++);
return *po;
*/
Polynominal& Polynominal::operator +(Polynominal& poly){
Polynominal* po=new Polynominal();
list<Term>::iterator iter1=pList.begin();
list<Term>::iterator iter2=poly.pList.begin();
while(iter1!=pList.end() && iter2!=poly.pList.end()){
if(iter1->exp < iter2->exp){
po->pList.push_back(*iter1++);
}
else if(iter1->exp > iter2->exp){
po->pList.push_back(*iter2++);
}
else{
Term* t=new Term(*iter1++ +*iter2++);//拷贝函数,且Term的相加已经重载过
po->pList.push_back(*t);
}
}
while(iter1!=pList.end()){
po->pList.push_back(*iter1++);
}
while(iter2!=poly.pList.end()){
po->pList.push_back(*iter2++);
}
return *po;
}