# 数据结构之一元多项式相乘

#include<stdio.h>
#include<malloc.h>
typedef struct Node
{
int coef;
int expn;
struct Node *next;
}List;
List *Creat()
{
p1=p2=(List *)malloc(sizeof(List));
scanf("%d%d",&p1->coef,&p1->expn);
p1->next=NULL;
while(p1->coef!=-1&&p1->expn!=-1)
{
else p2->next=p1;
p2=p1;
p1=(List *)malloc(sizeof(List));
scanf("%d%d",&p1->coef,&p1->expn);
}
p2->next=NULL;
}
{
List *p1,*p2,*p3,*p4;
p3=p4=(List *)malloc(sizeof(List));
p3->next=NULL;
while(p1)
{
while(p2)
{
p3->coef=p1->coef*p2->coef;
p3->expn=p1->expn+p2->expn;
p2=p2->next;
p4=p3;
p3=(List *)malloc(sizeof(List));
p4->next=p3;
}
p1=p1->next;
}
p4->next=NULL;
}
{
List *p1,*p2;
int coef,expn;
{
for(p2=p1->next;p2!=NULL;p2=p2->next)
{
if(p1->expn<p2->expn)
{
coef=p2->coef;
p2->coef=p1->coef;
p1->coef=coef;
expn=p2->expn;
p2->expn=p1->expn;
p1->expn=expn;
}
}
}
}
{
List *p1,*p2,*p3;
while(p1)
{
p2=p1->next;
while(p2)
{
if(p1->expn==p2->expn)
{
p3=p2->next;
p1->coef+=p2->coef;
p1->next=p3;
free(p2);
}
p2=p2->next;
}
p1=p1->next;
}
}
{
List *p;
while(p)
{
printf("%d %d ",p->coef,p->expn);
p=p->next;
}
printf("\n");
}
int main()
{