| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 1010 人关注过本帖
标题:请问哪里错了?
只看楼主 加入收藏
世遥
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-6-14
结帖率:0
  已结贴   问题点数:20  回复次数:2   
请问哪里错了?
#include<stdio.h>
#include<malloc.h>
typedef struct node{
float coef;
int expn;
node *next;
}Lnode, * Dxs;
Dxs create();
Dxs add_dxs(Dxs firsta, Dxs firstb);
void printDxs(Dxs h);
void deleteNode(Dxs h, Dxs p);
int main()
{
Dxs ha, hb, hc;
printf("请依次输入第一个多项式的系数和指数逗号隔开,以-1,-1结束\n");
ha = create();
printf("请依次输入第二个多项式的系数和指数逗号隔开,以-1,-1结束\n");
hb = create();
printf("输入的第一个多项式是: ");
printDxs(ha->next);
printf("输入的第二个多项式是: ");
printDxs(hb->next);
hc = add_dxs(ha, hb);
printf("两个多项式的和为: ");
printDxs(hc->next); return 0;
} //创建链表(读入数据以 0 0 结束)
Dxs create()
{
float coef;
int expn;
Dxs first, qa, s;
first = (Dxs)malloc(sizeof(Lnode));
first->coef = -1;
first->expn = -1;
first->next = NULL;
qa = first;
while(1)
{ scanf("%f,%d", &coef;&expn;)  
if(coef == -1 && expn == -1)
{ break; }
s = (Dxs)malloc(sizeof(Lnode));
s->coef = coef;
s->expn = expn;
s->next = NULL;
qa->next = s;
qa = s;
}
return first;
} //链表相加
Dxs add_dxs(Dxs firsta, Dxs firstb)
{
Dxs firstc, ha, hb, pc, s;
int a, b;
float sum;
firstc = (Dxs)malloc(sizeof(Lnode));
firstc->coef = -1;
firstc->expn = -1;
firstc->next = NULL;
pc = firstc; ha = firsta->next;
hb = firstb->next;
while(ha!= NULL && hb != NULL)
{ a = ha->expn;
b = hb->expn;
if(a>b)
{ //将a加入c中,移动a和c的指针
pc->next = ha;
pc = pc->next;
ha = ha->next;
}
else if(a > b)
{ //将b加入c中,移动b和c的指针
pc->next = hb;
pc = pc->next;
hb = hb->next;
}
else
{
sum = ha->coef + hb->coef;
if(sum != 0.0)
{ //将和加入a中,再将a加入c中,移动c的指针
ha->coef = sum;
pc->next = ha;
pc = pc->next;
}else
{ //查找删除A中系数之和为0的那个节点
s = firsta;
while(s != ha)
{ s = s->next;
}
s->next = ha->next;
} //ab已经处理完成,同时后移一位
ha = ha->next;
hb = hb->next;
}
} //将剩余部分加入c后面
if(ha != NULL)
{ pc->next = ha; }
if(hb != NULL)
{ pc->next = hb; }
return firstc;
} //遍历显示链表
void printDxs(Dxs h)
{ while(h != NULL)
{ printf("%0.2f*X^%d", h->coef, h->expn);
if(h->next)
{
printf("+");
}
h=h->next;
}
printf("\n");
}
搜索更多相关主题的帖子: include create 多项式 
2017-06-14 07:11
世遥
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-6-14
  得分:0 
aide上提示是第一句错误,但是不知道怎么改
2017-06-14 07:12
书生牛犊
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:星夜征程
等 级:城市猎人
威 望:9
帖 子:1073
专家分:5127
注 册:2015-10-27
  得分:20 
我就复制代码进去运行了一下,还没调试就发现了语法错误。。。
附件: 您没有浏览附件的权限,请 登录注册

φ(゜▽゜*)♪
2017-06-14 22:01
快速回复:请问哪里错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.113084 second(s), 8 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved