版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、班级:2011级计算机科学与技术一班姓名:弥沛学号:2011222223日期:2012年9月28日题目一:整理两个一元多项式相加程序代码:stdio.hstdiib.h struct node#i nclude#i ncludetyp edefint cof,exp;struct node * next; no de;void creat( struct node *h) int x,y;struct node *r, *p;r=h;printK input x,y:);scanf( %d,%d, &x, &y); while (x !=- 999)p=( struct node*)mallo
2、c( sizeof (struct no de); p- cof =x;p-ex p=y;r-n ext =p;r=p;scanf( %d,%d, &x, &y);r- next =NULL;void outline( struct node *h)struct node *p;p=h- n ext;while (p != NULL)void add (node *h1,node *h2) int x;struct node *r, * p, *q,*s;p=h1-n ext;q=h2- n ext;r=h1;while (p !=NUL&|!=NULL)ifrrP(P - expq- exp
3、)- next =p;=P;=p-n ext;printf( %dxA%d-,p - cof,p -e xp);p=p-n ext;printf( n); elserr q elsex=p-cof +q- cof;if (x =0)/s=p;p=p- n ext;/free(s);/s=q;q=q- n ext;/free(s);elsep- cof =x; r-n ext =p; r=p;if (p - expvq- exp )- next =q;=q;=q-n ext;ififp=Fh n ext;/s=q;q=q- n ext;/free(s);(p != NULL)r-n ext =p
4、;(q!=NULL)r-n ext =q;free(h2);运行结果:void main()struct node *h1,*h2;h1 =( structnode*)malloc( sizeof (structn ode);h2 =( struct node*)malloc( sizeof (struct no de);creat(h1);outli ne(h1);creat(h2);outli ne(h2);add(h1,h2);outli ne(h1); CrJM SOFTC VuYdfiXbinwwtem p. exeinput x y: 5, 4 6, 32 4, 1 L, 0-99
5、95s*4-6?:*3-5s*2-4x*l-lx*0-input X, y: 3, 3 5, 2 1, 0-9995x*3-5x*2-lx*0-ox - 4-11k3-10x2-4k1-2x O-Press any key to continue题目将两个有序单链表合并,并保持它的有序性题目二:单链表中数据的就地逆置。1、就地逆置代码:mai n()#include #include typedef struct Nodeint data;struct Node * n ext; Node, *LinkList;void create( struct Node *head)struct Nod
6、e *p, *q;int flag =1,x;p =head;printf( input x:);while (flag)q=( struct Node*)malloc( sizeof (struct Node); scanf( %d, &x);if (x !=- 999)q-data =x;p -n ext =q;p =p- n ext;elseflag =0;p -n ext =NULL; void NIZHI(Li nkList L) Node *p, *q; p =L- n ext;L- next =NULL; while (p !=NULL) 运行结果:q=p-n ext;p- n
7、ext =L- n ext;L- n ext =p;p=q;voidLin kList l;Node *p;l =(Node* )malloc( sizeof (Node);l - next = NULL;printf(请输入链表数据,以-999 结束!n);create(l);printf(输入的单链表为:n); p = I -next;while (p !=NULL)printf( %dn, p-data); p=p-n ext; NIZHI(l);printf(逆置后的单链表为:n);p = I -next;while (p !=NULL)printf( %dn,p-data); p=p
8、-n ext;scanf(- data =x;- n ext =NULL;- n ext =p;=p;%d, &x);node * p= head-next; n);(p !=NULL)#include #include struct nodeint data;struct node *next;void create( struct node * head)/*尾插法创建链表*/struct node *p, *r=head; int x;scanf(%d, &x);while (x !=- 999)p =( struct node*)malloc( sizeof (struct no de
9、);PPrrvoid outline(struct node *head)/*链表的输出*/structprintf(whileprintf( %5d, p-data);p =p- n ext;void mergelist( struct node *head1, struct node *head2) /*将两个有序链表合并*/struct node *p, *q, *r;=head1- n ext;=head2- n ext;=head1;while (p != NUL&|!= NULL)-n ext =p;=P;=p- next;-n ext =q;=q;=q- next;if (p- data v=q-data) rrP elserrqif (q =NULL)r -n ext = p; elser -n ext =q;mai n()struct node *head1, *head2; headl =( structnode*)malloc( sizeof (struct node);head2 =( structnode*)malloc( sizeof (struct node);head1 -n ext=NULL;head2 - next =NULL; create(head1);create(head2);printsout put arran ge
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 北京警察学院《Premiere 视频编辑》2024 - 2025 学年第一学期期末试卷
- 乡镇国土空间规划文本
- 护理法律法规知识课件
- 2026年虚拟现实技术在教育领域的实践报告及未来五至十年教育创新报告
- 新生儿常见意外伤害预防
- 【北师大版】初中生物学八年级上册 期末评估测试卷二(含答案)
- 全期护理的成本效益分析
- 2026年及未来5年中国锻造件行业市场深度分析及发展前景预测报告
- 基于生物识别技术的智能门禁与身份验证系统开发课题报告教学研究课题报告
- 2025年物联网在智能家居报告
- 2023-2024学年北京市海淀区清华附中八年级(上)期末数学试卷(含解析)
- 临终决策中的医患共同决策模式
- 2025年贵州省辅警考试真题附答案解析
- 半导体厂务项目工程管理 课件 项目6 净化室系统的设计与维护
- 防护网施工专项方案
- 2026年及未来5年市场数据中国聚甲醛市场运行态势及行业发展前景预测报告
- TCFLP0030-2021国有企业网上商城采购交易操作规范
- 2025广东省佛山市南海公证处招聘公证员助理4人(公共基础知识)测试题附答案解析
- (支行)2025年工作总结和2026年工作计划汇报
- 桂花香包制作课件
- 社会工作本科毕业论文
评论
0/150
提交评论