weixin_38517428 于 2018.02.13 23:04 提问

#include
#include
typedef int elemType;

typedef struct Node{
elemType Coefficient;
elemType Exponent;
struct Node *next;

int main()
{
printf("输入第一个多项式\n");
show(m);
printf("\n");
printf("输入第二个多项式\n");
show(n);
printf("\n");
printf("他们的积是\n");
ans= multi_list(m,n);
show(ans);
return 0;
}

{
return L->next==NULL;
}

{
Node *L;
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
Node *r;
r=L;
int k=n;
while(n--)
{
printf("请输入第%d项\n",k-n);
elemType coe,exp;
scanf("%d%d",&coe,&exp);
Node *p;
p=(Node *)malloc(sizeof(Node));
p->Coefficient=coe;
p->Exponent=exp;
r->next=p;
r=p;
}
r->next=NULL;
return L->next;
}

{
Node *L;
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
Node *r;
r=L;
while(a&&b)
{
Node *p;
p=(Node *)malloc(sizeof(Node));
if(a->Exponent>b->Exponent)
{
p->Exponent=a->Exponent;
p->Coefficient=a->Coefficient;
a=a->next;
r->next=p;
r=p;
}
else if(a->ExponentExponent)
{
p->Exponent=b->Exponent;
p->Coefficient=b->Coefficient;
b=b->next;
r->next=p;
r=p;
}
else
{
if((a->Coefficient+b->Coefficient)!=0)
{
p->Coefficient=a->Coefficient+b->Coefficient;
p->Exponent=b->Exponent;
r->next=p;
r=p;
}
a=a->next;
b=b->next;
}
}
if(a)
r->next=a;
else
r->next=b;
return L->next;
}

{
Node *L;
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
while(a)
{
Node *t;
t=(Node *)malloc(sizeof(Node));
t->next=NULL;
Node *r;
r=t;
while(b)
{
Node *p;
p=(Node *)malloc(sizeof(Node));
p->Coefficient=b->Coefficient*a->Coefficient;
p->Exponent=b->Exponent+a->Exponent;
r->next=p;
r=p;
b=b->next;
}
r->next=NULL;

``````    a=a->next;
printf("多项式当前是\n");
show(L->next);
printf("新链是\n");
show(t->next);

printf("多项式变为\n");
show(L->next);
}
return L->next;
``````

}
{
int i=1;
while(L)
{
printf("该多项式是%d 乘x的%d次方\n",L->Coefficient,L->Exponent);
L=L->next;
}
}

4个回答

rabbit_hog   2018.02.14 00:36

...//前面的省略
while(a)
{
Node *t;
t=(Node *)malloc(sizeof(Node));
t->next=NULL;
Node *r;
r=t;
Node *s;
s=b;
while(s)
{
Node *p;
p=(Node *)malloc(sizeof(Node));
p->Coefficient=s->Coefficient*a->Coefficient;
p->Exponent=s->Exponent+a->Exponent;
r->next=p;
r=p;
s=s->next;
}
r->next=NULL;
a=a->next;
}
...//后面省略

rabbit_hog 卧槽……我在代码里敲的空格都被吃了
10 天之前 回复
devmiao      2018.02.13 23:53
rabbit_hog   2018.02.14 00:51

rabbit_hog   2018.02.14 00:08