0
[待解决问题]

# include<stdlib.h>

typedef struct Node{
int term; //系数
int expon; //指数
struct Node next;
}Node,
List;

int n; List end,p;
L=(List )malloc(sizeof(Node));
L->next=NULL;
end=L;
printf("请输入需要输入的项数：");
scanf("%d",&n);
while(n--){
p=(List)malloc(sizeof(Node));
scanf("%d",&p->term);
scanf("%d",&p->expon);
end->next=p;
end = p;
}
end->next=NULL;
}

void print(List L){
List p=L;
while(p->next){
p=p->next;
if(p->term>0)
printf("+%dx^%d",p->term,p->expon);
else
printf("%dx^%d",p->term,p->expon);
}
putchar(10);
}
void insertnode(List &L,List p){
List q=L;
while(q->next!=NULL){
if(q->next->expon>p->expon) q->next;
else break;
}
if(q->next!=NULL&&q->next->expon==p->expon) q->next->term+=p->term;
else{
List c=(List)malloc(sizeof(Node));
c->expon=p->expon; c->term=p->term;
if(q->next==NULL) c->next=NULL; // 如果q是尾结点
else
c->next=q->next;
q->next=c;
}
}
List p=L2->next;
while(p!=NULL){
insertnode(L1,p); // 将L2的每一项插入到L1中
p=p->next;
}
free(L2);
}

int main(){
List pa,pb;
printf("请输入多项式L1 :\n");
print(pa);

``````printf("请输入多项式L2：\n");
print(pb);