有没有大佬帮忙看一下哪里出现了问题,编译没有错误却无法输出,知道的麻烦帮一下吧,多谢了!
#include<stdio.h>#include<malloc.h>
typedef struct Polynode
{
int coef;
int exp;
struct Polynode *next;
}Polynode,*Polylist;
Polylist PolyCreate();
void polyadd(Polylist polya,Polylist polyb);
void output(Polylist poly);
Polylist PolyCreate()
{
Polynode *head,*rear,*s;
int c,e;
head=(Polynode *)malloc(sizeof(Polynode));
rear=head;
printf("输入系数与指数,系数为零时结束\n");
scanf("%d,%d",&c,&e);
while(c!=0)
{
s=(Polynode *)malloc(sizeof(Polynode));
s->coef=c;
s->exp=e;
rear->next=s;
rear=s;
scanf("%d,%d",&c,&e);
}
rear->next=NULL;
return(head);
}
void output(Polylist poly)
{
Polynode *p;
p=(Polynode *)malloc(sizeof(Polynode));
p=poly->next;
while(p!=NULL)
{
if(p->exp=0)
{
if(p->coef>0)
printf("+%d",p->coef);
else
printf("%d",p->coef);
}
if(p->exp>0)
{
if(p->coef>0)
printf("+%d*x^%d",p->coef,p->exp);
else
printf("%d*x^%d",p->coef,p->exp);
}
p=p->next;
}
}
void polyadd(Polylist polya,Polylist polyb)
{
Polynode *p,*q,*tail,*temp;
int sum;
p=polya->next;
q=polyb->next;
tail=polya;
while(p!=NULL&&q!=NULL)
{
if(p->exp<q->exp)
{
tail->next=p;
tail=p;
p=p->next;
}
else if(p->exp==q->exp)
{
sum=p->coef+q->coef;
if(sum!=0)
{
p->coef=sum;
tail->next=p;
tail=p;
p=p->next;
temp=q;
q=q->next;
free(temp);
}
else
{
temp=p;
p=p->next;
free(temp);
temp=q;
q=q->next;
free(temp);
}
}
else
{
tail->next=q;
tail=q;
q=q->next;
}
}
if(p!=NULL)
tail->next=p;
else
tail->next=q;
}
int main()
{
Polynode *a,*b;
a=PolyCreate();
output(a);
b=PolyCreate();
output(b);
polyadd(a,b);
output(a);
return (0);
}