请问怎么修改代码让其能实现链表的多项式相加
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
typedef int ElemType;
typedef int Status;
typedef struct PNode
{
float coef;
int expn;
struct PNode *next;
}PNode,*Polynomial;
void Init(Polynomial &p)
{
p=new PNode;
p->next=NULL;
}
void CreatePolyn(Polynomial &p,int n)
{
PNode *l=p;
for(int i=0;i<n;i++)
{
PNode *q=new PNode;
q->next=NULL;
cout<<"请输入多项式系数:";
cin>>q->coef;
cout<<"请输入多项式指数:";
cin>>q->expn;
l->next=q;
l=q;
}
}
void AddPolyn(Polynomial &Pa,Polynomial &Pb)
{
Polynomial p1=Pa->next;
Polynomial p2=Pb->next;
Polynomial p3=Pa;
while(p1&&p2)
{
if(p1->expn==p2->expn)
{
sum= p1->coef+ p2->coef;
if(sum!=0)
{
p1->coef=sum;
p3->next=p1;
p3=p1;
p1=p1->next;
r=p2;
p2=p2->next;
delete r;
}
else
{
r=p1;
p1=p1->next;
delete r;
r=p2;
p2=p2->next;
delete r;
}
}
else if(p1->expn<p2->expn)
{
p3->next=p1;
p3=p1;
p1=p1->next;
}
else
{
p3->next=p2;
p3=p2;
p2=p2->next;
}
}
p3->next=p1?p1:p2;
delete Pb;
}
int main()
{
Polynomial Pa,Pb;
Init(Pa);
CreatePolyn(Pa,3);
Init(Pb);
CreatePolyn(Pb,4);
AddPolyn(Pa,Pb);
}