带表头结点一元多项式的创建、输出、撤销以及两个一元多项式相加和相乘
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#define ERROR 0
#define OK 1
#define Overflow 2
#define Underflow 3
#define NotPresent 4
#define Duplicate 5
typedef int ElemType;
typedef int Status;
//带表头结点一元多项式的定义
typedef struct pNode
{
int coef;
int exp;
struct pNode* link;
}pNode;
typedef struct
{
struct pNode *head;
}polynominal;
//带表头结点一元多项式的初始化
void Init(polynominal *p)
{
p->head=malloc(sizeof(pNode));
p->head->exp=-1;
p->head->link = NULL;
}
//带表头结点一元多项式的创建
void Create(polynominal *p)
{
pNode *pn,*pre,*q;
Init(p);
for(;;)
{
pn=malloc(sizeof(pNode));
printf("Input the coef of the polynomal:\n");//输入项数
scanf("%d",&pn->coef);
printf("Input the exp of the polynomal:\n");//输入指数
scanf("%d",&pn->exp);
if(pn->exp==0&&pn->coef==0)
break;
pre=p->head;
q=p->head->link;
while(q