




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选学习资料 - - - 欢迎下载试验报告一课程名称:数据结构试验名称:数据结构试验地点:运算机 110 机房专业班级:计科 z1501学号:2021001909同学姓名:刘元瑞指导老师:孟亮2021 年12月23日精品学习资料精选学习资料 - - - 欢迎下载1设次序表a 中的数据元素递增有序,试写一程序,将x 插入到次序表的适当位置上,使该表仍旧有序;2用单链表ha 储备多项式a ( x )=a0+a 1x 1+a2x2+anxn其中 ai 为非零系数 ,用单链表hb 储备多项式b ( x )=b0+b1x 1+b2 x2 +b mx m其中 bj 为非零系数 ,要求运算c( x )= a
2、 (x ) +b ( x ),结果存到单链表hc 中;试写出程序;#include <stdio.h>#include <malloc.h>typedef struct dxs int a;struct dxs *next;dxs、 *dxss;/ 函数声明部分void structure dxss head、 int n ;/多项式录入 void show dxss head ;/显示多项式void add dxss head1、 dxss head2、 dxss head3 ;/将多项式相加 void frees dxss head ;/释放储备空间void mai
3、ndxss ha、 hb、 hc; int n;/为多项式申请头结点空间ha = dxssmallocsizeofdxs; hb = dxssmallocsizeofdxs; hc = dxssmallocsizeofdxs;/从用户处录入多项式的参数printf" 请输入多项式1 的项数 n" scanf"%d"、 &n;structure ha、 n ;printf" 请输入多项式的2 项数 n" scanf"%d"、 &n;structure hb、 n ;/将多项式进行相加addha、 hb
4、、 hc;printf" 多项式 hc 的式子为 n"show hc ;/将构建的多项式显示出来 frees ha ;/释放掉申请的空间frees hb ; frees hc ; printf"nn"void structure dxss head、 int n /多项式录入精品学习资料精选学习资料 - - - 欢迎下载dxss p、 q; int a;printf" 请输入要录入系统的多项式的系数,从次数较小的开头n"p = head; doscanf"%d"、 &a ;q = dxssmalloc si
5、zeofdxs ; q->a = a;p->next = q;q->next = null; p = q;while-n;void show dxss head /显示多项式int m = 0; dxss p;p = head->next;while p .= null printf"%d*x%d"、 p->a、 m+ ; p = p->next;if p .= nullprintf"+"printf"n"/ 将多项式相加void add dxss head1、 dxss head2、 dxss h
6、ead3 dxss p、 q、 l、 m;p = head1->next; q = head2->next; l = head3;whilep .= null && q .= null m = dxssmallocsizeofdxs; m->a = p->a + q->a;m->next = null;l->next = m; l = m;p = p->next; q = q->next;while p .= null 精品学习资料精选学习资料 - - - 欢迎下载m = dxssmallocsizeofdxs; m->
7、;a = p->a;l->next = m; l = m;p = p->next;while q .= null m = dxssmallocsizeofdxs; m->a = q->a;l->next = m; l = m;q = q->next;l->next = null;void frees dxss head /释放储备空间dxss p、 q; p = head;while p .= null q = p;p = p->next; freeq;3设有 n 个人围坐在一个圆桌四周,现从第s 个人开头报数,数到第m 的人出列,然后从出
8、列的下一个人重新开头报数,数到m 的人又出列,如此重复,直到全部的人全部出列 为止; josephus 问题为:对于任意给定的n,m, s,求出按出列次序得到的n 个人员的次序表;精品学习资料精选学习资料 - - - 欢迎下载#include <stdio.h>#include <stdlib.h>#define false0#define true1typedef int datatype; struct node;typedef struct node *pnode; struct nodedatatype info;pnode link;typedef struc
9、t node *linklist; typedef linklist *plinklist;int init_clistplinklist pclist、 int npnode p、 q; int i;q = pnodemallocsizeofstruct node;if q = nullreturn false;*pclist = q; q->info = 1; q->link = q; if n = 1return true; for i = 2; i < n + 1; i+p = pnodemallocsizeofstruct node; if p = nullretu
10、rn false;p->info = i;p->link = q->link; q->link = p;q = p; return true;void josephus_clistplinklist pclist、 int s、 int mpnode p、 pre; int i;p =*pclist; if s = 1精品学习资料精选学习资料 - - - 欢迎下载pre = p;p = p->link;while p .=*pclist精品学习资料精选学习资料 - - - 欢迎下载elsepre = p;p = p->link;精品学习资料精选学习资料 -
11、- - 欢迎下载for i = 1; i < s; i+pre = p;p = p->link;while p .= p->linkfor i = 1; i < m; i+pre = p;p = p->link;printf" out element: %d n"、 p->info; if *pclist = p*pclist = p->link; pre->link = p->link; freep;p = pre->link;printf" out element: %d n"、 p->
12、;info;*pclist = null; freep;mainlinklist jos_clist; int n、 s、 m;doprintf"n please input the values of n = " scanf"%d"、 &n;while n < 1; do精品学习资料精选学习资料 - - - 欢迎下载printf" please input the values of s = " scanf"%d"、 &s;while s < 1; doprintf" please input the values of m = " scan
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年国际设计师考试新策略试题及答案
- 电气高数试题题库及答案
- 策划国际美术设计师考试目标试题及答案
- 国际商业美术设计师考试领域的启示试题及答案
- 助理广告师备考过程中的反思与小结试题及答案
- 社会人员面试试题及答案
- 广告设计师与市场团队的协作模式试题及答案
- 2024年纺织品检验员考试准备方法探讨试题及答案
- 2024年纺织工程师销售策略调整试题及答案
- 2024年智能纺织品试题及答案
- 水井清理淤泥施工方案
- 2024年黑龙江哈尔滨市中考英语真题卷及答案解析
- 【MOOC】道路交通安全-河海大学 中国大学慕课MOOC答案
- 地方融资平台债务和政府中长期支出事项监测平台操作手册-单位
- 2024年秋儿童发展问题的咨询与辅导终考期末大作业案例分析1-5答案
- 人教版二年级上册英语期中考试卷【3套】
- 过程审核表(产品组评分矩阵评审提问表(评分))-2024年百度过
- 二人合伙开餐饮店协议书范文电子版
- 国家职业技术技能标准 4-14-03-03 眼镜验光员 人社厅发2018145号
- 高速公路运营期保险方案
- 演唱会安保工作委托合同
评论
0/150
提交评论