主题:多项式加法!急!!!!
Node *addpolyn(struct Node*La,struct Node*Lb)
{
struct Node *p,*q,*head,*Lc,*t,*s;
int flag=1;
p=La->next;
q=Lb->next;
t=(struct Node *)malloc(sizeof(struct Node));
head=(struct Node *)malloc(sizeof(struct Node));
head->next=NULL;
t=head;
while(p&&q)
{
Lc=(struct Node *)malloc(sizeof(struct Node));
Lc->next=NULL;
// s=Lc;
if(p->expn==q->expn)
{
Lc->expn=q->expn;
Lc->coef=p->coef+q->coef;
if(Lc->coef==0)
free(Lc);
p=p->next;
q=q->next;
}
else if(p->expn>q->coef)
{
Lc->coef=q->coef;
Lc->expn=q->expn;
q=q->next;
}
else
{
Lc->coef=p->coef;
Lc->expn=p->expn;
p=p->next;
}
if(flag==1)
head->next=Lc;
t->next=Lc;
t=Lc;
++flag;
}
while(p)
Lc=p;
while(q)
Lc=q;
return (head);
}
那错了?调用此函数的时候加法做不了.老是光标在闪!!!
{
struct Node *p,*q,*head,*Lc,*t,*s;
int flag=1;
p=La->next;
q=Lb->next;
t=(struct Node *)malloc(sizeof(struct Node));
head=(struct Node *)malloc(sizeof(struct Node));
head->next=NULL;
t=head;
while(p&&q)
{
Lc=(struct Node *)malloc(sizeof(struct Node));
Lc->next=NULL;
// s=Lc;
if(p->expn==q->expn)
{
Lc->expn=q->expn;
Lc->coef=p->coef+q->coef;
if(Lc->coef==0)
free(Lc);
p=p->next;
q=q->next;
}
else if(p->expn>q->coef)
{
Lc->coef=q->coef;
Lc->expn=q->expn;
q=q->next;
}
else
{
Lc->coef=p->coef;
Lc->expn=p->expn;
p=p->next;
}
if(flag==1)
head->next=Lc;
t->next=Lc;
t=Lc;
++flag;
}
while(p)
Lc=p;
while(q)
Lc=q;
return (head);
}
那错了?调用此函数的时候加法做不了.老是光标在闪!!!