//ERROR TEST
//看样子不是创建这一步的问题
#include<stdio.h>
#include<iostream.h>
#include<malloc.h>
#include<cstdlib>
#include<math.h>
#include<string.h>
#define OK 1
#define ERROR 0
typedef int Status;
typedef struct PNode
{
float coef;//系数
int expn;//指数
struct PNode *next;//指针域
}PNode,*Polynomial;//多项式
Status CreatePolyn(Polynomial &P,int n)
{
P=(PNode *)malloc(sizeof(PNode));
//创建一个带头结点的单链表
if(!P) exit(OVERFLOW);
P->next=NULL;
PNode *q,*pre;//pre用于保存q的前驱,q用于遍历表结点
for(int i=1;i<=n;i++)
{
PNode *s=(PNode *)malloc(sizeof(PNode));
cin>>s->coef>>s->expn;
pre=P;
q=P->next;//首元结点
while(q&&q->expn<s->expn)
{
pre=q;
q=q->next;
}
s->next=q;
pre->next=s;
}
return OK;
}
Status ListShow(Polynomial P)
{
PNode *p;
p=P;
while(p->next!=NULL)
{
p=p->next;
cout<<p->coef<<"x^"<<p->expn<<endl;
}
return OK;
}
void main()
{
Polynomial PA;
cout<<"录入PA:"<<endl;
cout<<CreatePolyn(PA,3)<<endl;
cout<<"显示PA:"<<endl;
ListShow(PA);
}
// # 运行成功,录入正确#