谁能帮我改下这个程序
//多项式相加
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
float coef;
int expn;
struct node *next;
}PolyNode;
//创建一个多项式
void GreatPoly(PolyNode *&sq)
{
PolyNode*q=sq,*s;
int n,y,i=0;
float x;
sq=(PolyNode*)malloc(sizeof(PolyNode));
sq->next=NULL;
cout<<"请输入所要多项式项数:";
cin>>n;
cout<<endl;
cout<<"输入多项式:";
while(i<n)
{
cin>>x;
cin>>y;
s=(PolyNode*)malloc(sizeof(PolyNode));
s->coef=x;s->expn=y;
s->next=NULL;
q->next=s;
q=s;
i++;
}
cout<<"成功"<<endl;
}
//打印一个多项式
void DisPoly(PolyNode*sq)
{
PolyNode *p=sq->next;
while(p!=NULL)
{
cout<<"("<<p->coef<<","<<p->expn<<")";//<<"\t";
p=p->next;
}
cout<<endl;
}
//排序
void SortPoly(PolyNode*&sq)
{
PolyNode*p=sq->next,*pre,*q;
sq->next=NULL;
while(p!=NULL)
{
if(sq->next==NULL)
{
sq->next=p;
p=p->next;
sq->next->next=NULL;
}
else
{
pre=sq,q=pre->next;
while(q!=NULL&&p->expn>q->expn)
{
pre=q;q=q->next;
}
q=p->next;
p->next=pre->next;
pre->next=p;
p=q;
}
}
}
//相加
PolyNode *AddPoly(PolyNode*pa,PolyNode*pb)
{
PolyNode*pc,*p1=pa->next,*p2=pb->next,*tc,*s,*p;
pc=(PolyNode*)malloc(sizeof(PolyNode));
pc->next=NULL;
tc=pc;
while(p1!=NULL&&p2!=NULL)
{
if(p1->expn<p2->expn)
{
s=(PolyNode*)malloc(sizeof(PolyNode));
s->next=NULL;
s->coef=p1->coef;
s->expn=p1->expn;
tc->next=s;
tc=s;
p1=p1->next;
}
else if(p1->expn>p2->expn)
{
s=(PolyNode*)malloc(sizeof(PolyNode));
s->next=NULL;
s->coef=p2->coef;
s->expn=p2->expn;
tc->next=s;
tc=s;
p2=p2->next;
}
else
{
if(p1->coef+p2->coef!=0)
{
s=(PolyNode*)malloc(sizeof(PolyNode));
s->next=NULL;
s->coef=p1->coef+p2->coef;
s->expn=p1->expn;
tc->next=s;
tc=s;
}
p1=p1->next;p2=p2->next;
}
}
if(p1!=NULL) p=p1;
else p=p2;
while(p!=NULL)
{
s=(PolyNode*)malloc(sizeof(PolyNode));
s->next=NULL;
s->coef=p->coef;s->expn=p->expn;
tc->next=s;
tc=s;
p=p->next;
}
//tc->next=NULL;
return p;
}
void main()
{
PolyNode*sq1,*sq2,*sq3;
cout<<"两多项式相加运算:"<<endl;
GreatPoly(sq1);
SortPoly(sq1);
cout<<"排序后多项式A:";DisPoly(sq1);
GreatPoly(sq2);
SortPoly(sq2);
cout<<"排序后多项式B:";DisPoly(sq2);
sq3=AddPoly(sq1,sq2);
cout<<"两多项式相加结果为:";DisPoly(sq3);
}