这个创建一元多项式的程序怎么运行不了啊?
#include <iostream>using namespace std;
typedef struct{
float coef;
int expn;
}term,ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
typedef LinkList polynomial;
void InitList_L(LinkList &head)
{
head=new LNode;
head->next=NULL;
}
void CreatPolyn(polynomial &P,int m);void CreatPolyn(polynomial &P,int m)
{
InitList_L(P);
polynomial q1,q2;
term e;
P->data.coef=0.0;P->data.expn=-1;
q1=P;
for(int i=1;i<=m;i++)
{
cin>>e.coef>>e.expn;
while(e.expn>q1->next->data.expn&&q1->next)
q1=q1->next;
q2=new LNode;
q2->data.coef=e.coef;q2->data.expn=e.expn;
q2->next=q1->next;q1->next=q2;
}
}
void PrintPolyn(polynomial P)
{
while(P->next!=NULL)
{
cout<<"("<<P->data.coef<<","<<P->data.expn<<") ";
P=P->next;
}
cout<<endl;
}
int main()
{
polynomial pa,pb;
CreatPolyn(pa,4);CreatPolyn(pb,6);
cout<<"output pa:"<<endl;
PrintPolyn(pa);
cout<<"output pb:"<<endl;
PrintPolyn(pb);
return 0;
}