#include <stdio.h>
#include <stdlib.h>
typedef struct polynode {
int coef;
int exp;
struct polynode *next;
}PNode;
PNode *Creat_Linkst(int n) {
PNode *head,*p,*s;
int i;
//head=(PNode *)malloc(sizeof(PNode));
head=new(PNode);
head->next=NULL;
p=head;
printf("enter coef,exp:\n");
for (i=1;i<=n;i++){
//s=(PNode *)malloc(sizeof(PNode));
s=new(PNode);
scanf("%d,%d",&s->coef,&s->exp);
s->next= _______ ;
p->next= ________ ;
p=______-;
}
return(head);
}
void PolyAdd(PNode *pa,PNode *pb){
PNode *pre,*qa,*qb,*q;
int sum;
pre=pa;
qa=pa->next; qb=pb->next;
while ( _____ ) {
if ( ____ ){
sum= _____ ;
if (sum){
qa->coef= ______ ;
pre=qa;
}
else{
pre->next= ______ ;
free(qa);
}
qa=pre->next;
q=qb;
qb= ;
free(q);
}
else {
if(qa->exp>qb->exp) {
pre= ______ ;
qa= ______ ;
}
else {
pre->next= _______ ;
pre= ______ ;
qb= _______ ;
pre->next=qa;
}
}
}
if (qb) pre->next= _________ ;
free(pb);
}
void Print_Linkst(PNode *H) {
PNode *p;
p=H->next;
while (p->next) {
printf("%dx^%d+",p->coef,p->exp);
_______________ ;
}
if (p->exp)
printf("%dx^%d\n",p->coef,p->exp);
else
printf("%d\n",p->coef);
}
main()
{PNode *HA,*HB;
int la,lb;
printf("enter la,lb:");
scanf("%d,%d",&la,&lb);
printf("\ncreat HA\n");
HA=Creat_Linkst(la);
printf("A(x)=");
Print_Linkst(HA);
HB=Creat_Linkst(lb);
printf("B(x)=");
Print_Linkst(HB);
PolyAdd(HA,HB);
printf("\nA(x)+B(x)=");
Print_Linkst(HA);
}