多项式加法,不知道哪里有问题,找了很久没找出来,能不帮个忙看下

#include
#include
typedef int ElemType;
typedef struct node{
ElemType exp;
ElemType coef;
struct node next;
}linklist;
//创建空链表,再主函数里输入数值,
void creat(linklist *s)
{
s=(linklist
)malloc(sizeof(linklist));
s->next=NULL;
}
//删除整个链表
void deletelinklist(linklist s)
{
linklist *pre,*p=s->next;
while(p!=NULL)
{
free(pre);
pre=p;
p=p->next;
}
free(pre);
}
//插入某一个结点
void insert(linklist *s,ElemType e1,ElemType e2)
{
linklist *p=NULL,*q=NULL;
q=s;
p=(linklist
)malloc(sizeof(linklist));
p->coef=e1;
p->exp=e2;
p->next=q->next;
q->next=p;
}//删除某一个结点
void deletenode(linklist s,ElemType e1,ElemType e2)
{
linklist *p=s,*q;
q=p->next;
while(p!=NULL && q->coef!=e1 &&q->exp!=e2)
{
p=p->next;
q=q->next;
}
if(q->coef==e1 && q->exp==e2 )
{
p->next=q->next;
free(q);
}
}
//加法
linklist
jiafa(linklist *s1,linklist *s2,linklist *s3)
{
linklist *p=s1,*q=s2,*p3=s3;;

while(p!=NULL&&q!=NULL)
{
if(p->expexp)
{

insert(s3,p->coef,p->exp);
p=p->next;
}
if(p->exp>q->exp)
{
insert(s3,q->coef,q->exp);
q=q->next;
}
if(p->exp==q->exp)
{
if(p->coef+q->coef==0)
{
p=p->next;
q=q->next;
}
else
{
p->coef=p->coef+q->coef;
insert(s3,p->coef,p->exp);
p=p->next;
q=q->next;
}
}
}
return s3;
}
void print(linklist *s)
{
linklist *p=s;
while(p!=NULL)
{
printf("%d %d",p->coef,p->exp);
p=p->next;
}
}
int main()
{
linklist s1,s2,*s3=NULL;
int n,t,i;
scanf("%d",&n);
creat(&s1);
creat(&s2);
creat(s3);
for(i=0;i {
while((t=scanf("%d%d",&s1.coef,&s1.exp))==2 && s1.exp>=0 )
{
insert (&s1,s1.coef,s1.exp);
}

while((t=scanf("%d%d",&s2.coef,&s2.exp))==2 &&  s2.exp>=0 )
{
  insert (&s2,s2.coef,s2.exp);
}

s3=jiafa(&s1,&s2,s3);
 print(s3);

}
return 0;

}

先不看函数,只看结构体定义的话,po主没有贴错?
struct node next;

如果定义链表的话,这个next应该是个指针?po主现在相当于在node结构体里无限嵌套定义了node结构体。

creat函数分配空间也错误,从creat函数的调用来看,creat函数中的空间分配纯属多余,而且造成了内存泄漏。

是struct node *next

改了一下不过还是和有问题
#include
#include
typedef int ElemType;
typedef struct node{
ElemType exp;
ElemType coef;
struct node next;
}linklist;
struct node *creat( )
{
struct node *p1,*head1,*p2;
head1=(struct node
)malloc(sizeof(struct node));
p1=(struct node*)malloc(sizeof(struct node));
scanf("%d %d",&p1->coef,&p1->exp);
head1->next=p1;
p1->next=NULL;
while(1)
{
p2=(struct node*)malloc(sizeof(struct node));
scanf("%d %d",&p2->coef,&p2->exp);
if(p2->exp break;
p1->next=p2;
p2->next=NULL;
p1=p2;
}
return(head1);
}
linklist add(linklist *s1,linklist *s2)
{
linklist *s=NULL;
linklist *p,*q;
linklist *p3;
linklist *rearc;
rearc=s;
p=s1->next;
q=s2->next;
while(q!=NULL&&p!=NULL)
{
if(p->exp==q->exp)
{
if(p->coef+q->coef!=0)
{
p3=(linklist *)malloc(sizeof(linklist));
p3->coef=p->coef+q->coef;
p3->exp=p->exp;
p3->next=NULL;
rearc->next=p3;
rearc=p3;
}
p=p->next;
q=q->next;
}
if(p->expexp)
{
p3=(linklist
)malloc(sizeof(linklist));
p3->coef=p->coef;
p3->exp=p->exp;
p3->next=NULL;
rearc->next=p3;
rearc=p3;
p=p->next;
}
if(p->exp>q->exp)
{
p3=(linklist*)malloc(sizeof(linklist));
p3->coef=q->coef;
p3->exp=q->exp;
p3->next=NULL;
rearc->next=p3;
rearc=p3;
q=q->next;
}
}
while(p!=NULL)
{

p3=(linklist*)malloc(sizeof(linklist));
p3->coef=p->coef;
p3->exp=p->exp;
p3->next=NULL;
rearc->next=p3;
rearc=p3;
p=p->next;
}
while(q!=NULL)
{
p3=(linklist*)malloc(sizeof(linklist));
p3->coef=q->coef;
p3->exp=q->exp;
p3->next=NULL;
rearc->next=p3;
rearc=p3;
q=q->next;
}
return s;
}
void BubbleSort(linklist *head)

{

linklist *i=NULL,*j=NULL;

int temp_exp;

int temp_coef;

for(i = head->next; i!= NULL; i = i -> next)

for(j=i->next; j!=NULL; j=j->next)

if(i->exp>j->exp)

{

temp_exp=j->exp;

temp_coef=j->coef;

j->coef=i->coef;

j->exp=i->exp;

i->exp=temp_exp;

i->coef=temp_coef;

}

}

void print(linklist *head)
{
linklist *current;
current = head->next;
while(current!=NULL)
{
if(current->coef!=0)
{
printf("%d %d ",current->coef,current->exp);
}
current=current->next;
}
printf("\n");
}
int main()
{
linklist *s1,*s2,*s3;
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
s1=creat();
BubbleSort(s1);
print(s1);
s2=creat();
BubbleSort(s2);
print(s2);
s3=add(s1,s2);
BubbleSort(s3);
print(s3);
}
return 0;
}