单链表实现一元多项式相加请帮我看一下这个程序有什么错误,#include #include #include #include #include #include #include #include #include typedef struct LNode{ /*多项式的存储结构定义*/int coef;int expn;struct LNode

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 23:52:40
单链表实现一元多项式相加请帮我看一下这个程序有什么错误,#include #include #include #include #include #include #include #include #include typedef struct LNode{ /*多项式的存储结构定义*/int coef;int expn;struct LNode
xV]OG+WX6l궏1+RUr޵M ,!@(j &N UHQHR/:3;;;**!3{{;g.1>r |?zz _o7w_MoߴMxuKA{IV p]mF4y t'PY߅/|{rv{jfx`,V?aVRyO^-d NF&D,dc_$?L[BӷEkEVŮof@Jy%|v5c`fq" RԴ\ѨsZ>O,a@w+1+9Shb@q u]e2Ԃ:9dGw\| 2 8>ca]O" *;nQ$G4(:<HCL" ʶ~ά9GfYFFGQS!6=Y=` <$zD=qOZQޥkwj1vHlRr'::B9Nr$vQiL#%B*3V$6 R 0oG*;vz)=#~()vYoBV.,WU =1zylui4vOnޣ)2v$oQ\M#p,:Qe Y4pקnʌ~^2n4(H‚] :܋།-p} IdNV]l >{ rl{_!ӇyӦ-{qڈۧz_ {% .}}vrpu\G>zKnv{Ecy|t >o䟇0oF?o!f@j D~T'@jp-")ːYL 䂎< 'dWPh$H4ЀN UZ{J&8#B WjҸ6ըk“lDI9G\dL13! 3 W <(]j0A7E5AD)"X^܈eHZiF5 #A+DP rJ0U \L֔Y[L$U,gh4!LԌӚHj΀> vW;hR<8U6D)׊&O3Re!b4%:@'kagE0Z [JXi1O

单链表实现一元多项式相加请帮我看一下这个程序有什么错误,#include #include #include #include #include #include #include #include #include typedef struct LNode{ /*多项式的存储结构定义*/int coef;int expn;struct LNode
单链表实现一元多项式相加
请帮我看一下这个程序有什么错误,
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct LNode
{ /*多项式的存储结构定义*/
int coef;
int expn;
struct LNode *next;
}LNode,*polynomail;
void creatpolyn(polynomail &p,int m)
{
int i;
int coef;
int expn;
polynomail s;
p=(polynomail)malloc(sizeof(LNode));
p->next = NULL;
for(i=1;icoef,s->expn);
printf("\n");
s->coef=coef;
s->expn=expn;
s->next=p->next;
p->next=s;
}
}//CreatPolyn
void addpolyn(polynomail &pa,polynomail &pb)
{
polynomail qa,qb,c,pc;
pc=(polynomail)malloc(sizeof(LNode));
pc->next=NULL;
qa=pa->next;
qb=pb->next;
while(qa&&qb)
{
if(qa->expn=qb->expn)
{
c=(polynomail)malloc(sizeof(LNode));
c->expn=pa->expn;
c->coef=qa->coef+qb->coef;
c->next=NULL;
qa=qa->next;
qb=qb->next;
}
if(qa->expn>qb->expn)
{
c=(polynomail)malloc(sizeof(LNode));
c->expn=qa->expn;
c->coef=qa->coef;
c->next=NULL;
qa=qa->next;
}
if(qa->expnexpn)
{
c=(polynomail)malloc(sizeof(LNode));
c->expn=qb->expn;
c->coef=qb->coef;
c->next=NULL;
qb=qb->next;
}
pc->next=c;
pc=c;
}//while
if(qa)
c->next=qa;
else
c->next=qb;
}//AddPolyn
void printpolyn(polynomail p)
{
while(p->next!=NULL)
{
p=p->next;
printf(" %g*x^%d",p->coef,p->expn);
}
}
int main()
{
int n,m;
polynomail pa,pb;
printf("请输入一元多项式pa的项数:");
scanf("%d\n",n);
printf("\n");
creatpolyn(&pa,n);
printf("请输入一元多项式pb的项数:");
scanf("%d\n",m);
printf("\n");
creatpolyn(&pb,m);
addpolyn(&pa,&pb);
printf("结果是:pa+pb=");
printpolyn(pa);
printf("\n");
return 0;
}

单链表实现一元多项式相加请帮我看一下这个程序有什么错误,#include #include #include #include #include #include #include #include #include typedef struct LNode{ /*多项式的存储结构定义*/int coef;int expn;struct LNode
我希望你能给我加分啥,我帮你调试了大概2个小时了.
这程序是不是你写的?
如果是的话,希望你好好加强C的基本功,很多思想上和语法上的问题.
其实我也不是帮你改,基本上我帮你重写了.
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct LNode
{ /*多项式的存储结构定义*/
int coef;
int expn;
struct LNode *next;
}LNode,*polynomail;
void creatpolyn(polynomail &p,int m)
{
printf("creatpolyncreatpolyncreatpolyncreatpolyny\n");
int i;
int coef;
int expn;
polynomail s;
p=(polynomail)malloc(sizeof(LNode));
p->next=NULL;
for(i=1;icoef=coef;
s->expn=expn;
s->next=p->next;
p->next=s;
}
}//CreatPolyn
polynomail addpolyn(polynomail &pa,polynomail &pb)
{
polynomail c,pc;
pc=(polynomail)malloc(sizeof(LNode));
pc->next=NULL;
pa=pa->next;
pb=pb->next;
while(pa && pb)
{
if((pa->expn)==(pb->expn))
{
c=(polynomail)malloc(sizeof(LNode));
c->expn=pa->expn;
c->coef=((pa->coef)+(pb->coef));
pa=pa->next;
pb=pb->next;
} //if
else if((pa->expn)>(pb->expn))
{
c=(polynomail)malloc(sizeof(LNode));
c->expn=pb->expn;
c->coef=pb->coef;
pb=pb->next;
} //if
else
{
c=(polynomail)malloc(sizeof(LNode));
c->expn=pa->expn;
c->coef=pa->coef;
pa=pa->next;
} //if
c->next=pc->next;
pc->next=c;
}//while
if(!pa && pb)
{ while(c->next!=NULL)
{
c=c->next;
}//while
c->next=pb; }
if(!pb && pa)
{ while(c->next!=NULL)
{
c=c->next;
}//while
c->next=pa;}
return pc;
}//AddPolyn
void printpolyn(polynomail &p)
{
while(p->next!=NULL)
{ printf("test_print");
p=p->next;
printf(" %dX^%d+ ",p->coef,p->expn);
printf("\n");
}//while
}//printpolyn
void main(void)
{
int n,m;
polynomail pa,pb,pc;
printf("请输入一元多项式pa的项数:");
scanf("%d",&n);
creatpolyn(pa,n);
printf("请输入一元多项式pb的项数:");
scanf("%d",&m);
creatpolyn(pb,m);
pc=addpolyn(pa,pb);
printf("结果是:pa+pb=\n");
printpolyn(pc);
}