一元多项式
#include<stdio.h>#include<stdlib.h>
#include "Status.h"
//typedef int LElemType;
//#include"SqList.h"
//typedef SqList mySetType;
typedef struct polyNode{
float coef;
int exp;
struct polyNode *next,*prior;
}*poly;
//typedef x ElemType;
poly creatSet(int n,float m)
{
int i;
poly pnew,phead,ptail;
phead=(poly )malloc(sizeof(poly)); //为链表设计一个头结点
phead->coef=m;
phead->exp=n;
phead->next =NULL;
phead->prior =NULL;
ptail=phead;
for(i=0;i<n;i++){
printf("输入第 %d 个数 :",i+1);
pnew=(poly )malloc(sizeof(poly));//生成头结点,尾插法
scanf("%d",& pnew->coef);
scanf("%d",& pnew->exp);
ptail->next =pnew ;
pnew->prior =ptail;
ptail=pnew;
ptail->next =NULL;
}
return phead;
}
void polyAdd(poly &A,poly &B)
{
poly pa=A->next,pb=B->next,rear=A, q;
while(pa&&pb){
if(pa->exp<pb->exp)
rear->next=pa;
rear=pa;
pa=pa->next;
}
else if (pa->exp>pb->exp){
rear->next=pb;
rear=pb;
pb=pb->next;
}
else{
pa->coef+=pb->coef;
if(pa->coef!=0.0){
rear->next=pa;
rear=pa;
pa=pa->next;
q=pb;
pb=pb->next;
free(q);
}
else{
q=pa;
pa=pa->next;
free(q);
q=pb;
pb=pb->next;
free(q);
}
}
}
if(pa)rear->next=pa;
else rear->next=pb;
free(B);
}
void main(){
ploy A,B;
int n;
float m;
scanf("%d",n);
scanf("%f",m);
A=creatSet( n,m);
B=creatSet( n,m);
polyAdd( &A, &B);
}
有谁帮着看看这个一元多项式的创建加减呀,我实在不会了