POLY *exception(ha,hb)
POLY *ha,*hb;
{
POLY *hc,*pA,*pB,*pAp,*pC,*pCp,*pT,*pD;
int COUNT=0;
hc=NEW;
hc->next=hc;
pCp=hc;
while(1)
{
COUNT++;
pC=NEW;
pAp=ha;
ha->coef=-9999999;
ha->exp=-9999999;
pA=pAp->next;
pB=hb->next;
if(pA->exp>=pB->exp)
{
pC->exp=pA->exp-pB->exp;
pC->coef=pA->coef*pB->coefs;
pC->coefs=pA->coefs*pB->coef;
}
else
{
free(pC);
break;
}
pCp->next=pC;
pCp=pCp->next;
pCp->next=hc;
pD=pA;
pA=pA->next;
pAp->next=pA;
pB=pB->next;
free(pD);
while(pB!=hb)
{
if(pA->exp>(pB->exp+pC->exp))
{
while(pA->next->exp>(pB->exp+pC->exp))
pA=pA->next;
if(pA->next->exp==(pB->exp+pC->exp))
{pA->next->coef=pA->next->coef-(pB->coef*pC->coef);
if(pA->next->coef==0)
{
pD=pA->next;
pA->next=pA->next->next;
free(pD);
}
}
else
{
pT=NEW;
pT->exp=pB->exp+pC->exp;
pT->coef=-pB->coef*pC->coef;
pT->coefs=pB->coefs*pC->coefs;
pT->next=pA->next;
pA->next=pT;
}
pA=pAp->next;
}
else if(pA->exp==(pB->exp+pC->exp))
{
pA->exp=pA->exp;
pA->coef=pA->coef*pB->coefs*pC->coefs-pA->coefs*pB->coef*pC->coef;
pA->coefs=pA->coefs*pB->coefs*pC->coefs;
}
else if(pA->exp<(pB->exp+pC->exp))
{
pT=NEW;
pT->exp=pB->exp+pC->exp;
pT->coef=-pB->coef*pC->coef;
pT->coef=-pB->coefs*pC->coefs;
pT->next=pA; /*copy *pB to ha*/
pAp->next=pT;
pAp=pT;
}
if(pA->coef==0)
{
pD=pA;
pA=pA->next;
pAp->next=pA;
free(pD);
}
else
{
pAp=pA;
pA=pA->next;
}
pB=pB->next;
}
pB=hb->next;
pA=ha->next;
pAp=ha;
printf("This is the %d turn\n",COUNT);
printf("The result poly is:\n");
print_poly(hc);
printf("The poly A is:\n");
print_poly(ha);
}
return(hc);
}
[求助]找错,谢谢