链表实现合并同类项?
作者:互联网
***暂定,待修改***
/*Polynomial为结构体别名,P1传入表头,expon为指数,coef为常系数*/
Polynomial Check(Polynomial P1) {
for (Polynomial i=P1;i!=NULL;i=i->link)
for (Polynomial j=i->link;j!=NULL;j=j->link)
if (i->expon = j->expon)
{
j->coef += i->coef;//指数相同系数相加
Polynomial point=P1;
while (point->link&&point->link != i)
point = point->link;//寻找i的直接前驱
point->link = point->link->link;
point->link->link = NULL;//从表中删除i
}
return P1;
}
标签:expon,P1,point,同类项,合并,链表,link,Polynomial,NULL 来源: https://blog.csdn.net/qq_43732324/article/details/100885054