ImageVerifierCode 换一换
格式:DOCX , 页数:38 ,大小:32.09KB ,
资源ID:8174122      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8174122.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(算法与数据结构实验报告讲诉.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

算法与数据结构实验报告讲诉.docx

1、算法与数据结构实验报告讲诉学 生 实 验 报 告 册课程名称:算法与数据结构实验项目名称: 顺序表 实验学时: 2 同组学生姓名: 实验地点: 工科楼A205 实验日期: 2013年10月16日 实验成绩: 批改教师: 批改时间: 实验1 顺序表一、实验目的和要求掌握顺序表的定位、插入、删除等操作。二、实验仪器和设备Turbo C 2.0三、实验内容与过程(含程序清单及流程图)1、必做题(1) 编写程序建立一个顺序表,并逐个输出顺序表中所有数据元素的值。编写主函数测试结果。(2) 编写顺序表定位操作子函数,在顺序表中查找是否存在数据元素x。如果存在,返回顺序表中和x值相等的第1个数据元素的序号

2、(序号从0开始编号);如果不存在,返回1。编写主函数测试结果。(3) 在递增有序的顺序表中插入一个新结点x,保持顺序表的有序性。解题思路:首先查找插入的位置,再移位,最后进行插入操作;从第一个元素开始找到第一个大于该新结点值x的元素位置i即为插入位置;然后将从表尾开始依次将元素后移一个位置直至元素i;最后将新结点x插入到i位置。(4) 删除顺序表中所有等于X的数据元素。2、选做题(5) 已知两个顺序表A和B按元素值递增有序排列,要求写一算法实现将A和B归并成一个按元素值递减有序排列的顺序表(允许表中含有值相同的元素)。程序清单:1、#define maxsize 100typedef stru

3、ct int datamaxsize; int last;sequenlist;main() int i; sequenlist l=2,5,6,8,2,8,4,3,7; printf(nThe list is:); for(i=0;i=l.last;i+) printf(%2d,l.datai);2、#define maxsize 100typedef struct int datamaxsize; int last;sequenlist;main() int x,i,s=-1; sequenlist l=2,5,6,7,9,8,4,3,7; printf(nThe list is:); f

4、or(i=0;i=l.last;i+) printf(%2d,l.datai); printf(nPlease input the number :); scanf(%d,&x); for(i=0;i=l.last;i+) if(l.datai=x) s=i;break; printf(%d,s);3、#define maxsize 100typedef struct int datamaxsize; int last;sequenlist;main() int i,x,j; sequenlist l=1,3,5,6,7,9,5; printf(nThe list is:); for(i=0;

5、i=l.last;i+) printf(%2d,l.datai); printf(nInput the insert number:); scanf(%d,&x); for(i=1;ix) break; for(j=l.last;j=i-1;j-) l.dataj+1=l.dataj; l.datai-1=x; l.last+; printf(the list after insertion is:n); for(j=0;j=l.last;j+) printf(%3d,l.dataj);4、#define maxsize 100typedef struct int datamaxsize; i

6、nt last;sequenlist;main() int i,j,x=0,k=0; sequenlist L=1,3,5,7,2,4,6,8,2,9,9; printf(n The list is:); for(i=0;i=L.last;i+) printf(%3d,L.datai); printf(nPlease input a number x:); scanf(%d,&x); for(i=1;i=L.last+1;i+) if(L.datai-1=x) for(j=i;j=L.last+1;j+) L.dataj-1=L.dataj; L.last-; i-; k=1; if(k=1)

7、 printf(The list after deletion is:n); for(j=0;j=L.last;j+) printf(%3d,L.dataj); else printf(Not found!n);四、实验结果与分析(程序运行结果及其分析)1、输出结果:The list is: 2 5 6 8 2 8 4 32、输出结果:The list is: 2 5 6 7 9 8 4 3 Please input the number:8 5The list is: 2 5 6 7 9 8 4 3 Please input the number:1 -13、输出结果:The list is

8、: 1 3 5 6 7 9 Input the insert number:8 The list after insertion is: 1 3 5 6 7 8 94、输出结果:The list is: 1 3 5 7 2 4 6 8 2 9 Please input a number x:5 The list after deletion is: 1 3 7 2 4 6 8 2 9 The list is: 1 3 5 7 2 4 6 8 2 9 Please input a number x:11 Not found!五、实验体会(遇到问题及解决办法,编程后的心得体会)遇到问题:读取数据元

9、素时,误将=写成=,导致错误。实验过程中,顺序表的赋值没有弄懂,以致输出多个0或者少输出。格式运算符也要正确控制,否则系统会停止工作。实验体会:通过实验掌握了顺序表的基本操作,如初始化、插入、读取元素、删除等等。并了解到线性表顺序存储结构的特点,即逻辑关系上相邻的两个元素在物理位置上也相邻,然而从另一方面来看,在做插入和删除时需要移动大量元素。本次实验基本完成了实验要求的目的,顺序表的初始化,定义,插入,查找等,更好的了解了顺序表基本操作的算法,以及更直观的了解了数据结构在C语言环境下的体现。实验项目名称: 单链表 实验学时: 2 同组学生姓名: 实验地点: 工科楼A205 实验日期: 201

10、3年10月23日 实验成绩: 批改教师: 批改时间: 实验2 单链表一、实验目的和要求1、实验目的掌握单链表的定位、插入、删除等操作。2、实验要求(1)注意链表的空间是动态分配的,某结点不用之后要及时进行物理删除,以便释放其内存空间。(2)链表不能实现直接定位,一定注意指针的保存,防止丢失。二、实验仪器和设备Turbo C 2.0三、实验内容与过程(含程序清单及流程图)1、必做题(1) 编写程序建立一个单链表,并逐个输出单链表中所有数据元素。(2) 在递增有序的单链表中插入一个新结点x,保持单链表的有序性。解题思路:首先查找插入的位置然后进行插入操作;从第一个结点开始找到第一个大于该新结点值的

11、结点即为插入位置;然后在找到的此结点之前插入新结点;注意保留插入位置之前结点的指针才能完成插入操作。(3) 编写实现带头结点单链表就地逆置的子函数,并编写主函数测试结果。2、选做题已知指针LA和LB分别指向两个无头结点单链表的首元结点。要求编一算法实现,从表LA中删除自第i个元素起共len个元素后,将它们插入到表LB中第j个元素之前。程序清单:1、#includetypedef int datattype;typedef struct node char data; struct node *next;linklist;main() char ch;linklist *head,*s,*r,*

12、p; head=malloc(sizeof(linklist); r=head; scanf(%c,&ch); while(ch!=$) s=malloc(sizeof(linklist); s-data=ch; r-next=s; r=s; scanf(%c,&ch); r-next=NULL; r=head-next; while(r!=NULL) printf(%c,r-data); r=r-next; 2、#include stdio.h#include stdlib.htypedef struct node int data; struct node *next;linklist;m

13、ain() int x,y; linklist *head,*s,*r,*p,*q,*m,*n; clrscr(); head=malloc(sizeof(linklist); r=head; printf(input the order numbers :); scanf(%d,&x); while(x!=0) s=malloc(sizeof(linklist); s-data=x; r-next=s; r=s; scanf(%d,&x); r-next=NULL; printf(Please input the insert value:); scanf(%d,&y); p=head-ne

14、xt; while(p!=NULL) if (p-datanext; else break; q=malloc(sizeof(linklist); q-data=y; m=head; while(m-next!=p) m=m-next; q-next=p; m-next=q; n=head-next; printf(the list are:); while(n!=NULL) printf(%3d,n-data); n=n-next; 3、#include stdio.h#include stdlib.htypedef struct node int data; struct node *ne

15、xt;linklist;main() int a; linklist *head,*s,*r,*p,*q,*t; clrscr(); head=malloc(sizeof(linklist); r=head; printf(Input some numbers:); scanf(%d,&a); while(a!=0) s=malloc(sizeof(linklist); s-data=a; r-next=s; r=s; scanf(%d,&a); r-next=NULL; printf(n The linklist before changed is:n ); p=head-next; whi

16、le(p) printf(%d,p-data); p=p-next; p=head-next; q=p-next; while(q!=NULL) t=q-next; q-next=p; p=q; q=t; head-next-next=NULL; head-next=p; printf(nAfter changed:n); p=head-next; while(p!=NULL) printf(%d,p-data); p=p-next; 四、实验结果与分析(程序运行结果及其分析)1、输入:1 2 3 a b c $输出结果:1 2 3 a b c 2、输入:input the order num

17、bers : 1 3 5 7 8 9 0Please input the insert value::4 输出结果:the list are: 1 3 4 5 7 8 93、输入:Input some numbers:1 3 4 5 8 0 输出结果:The linklist before changed is: 13458After changed: 85431五、实验体会(遇到问题及解决办法,编程后的心得体会)遇到问题:编写成功后运行时,没有加入$导致程序运行不成功,不能够退出。后注意到这个问题才继续运行下去。实验体会:在编写程序时,设置了结束字符一定要牢牢记住,并且在输入时观察仔细类型是

18、什么,以及是否是输入一串有顺序的数字,编写成功不难,但是要规范格式,不能仅仅以完成程序为目的。而完成这一章的实验也让我了解了,顺序表便于查找不便于插入删除,而链表恰恰相反,链表的插入删除只需要移动指针,而顺序表要从后往前依次移动,二者各有优劣。实验项目名称: 堆栈和队列 实验学时: 2 同组学生姓名: 实验地点: 工科楼A205 实验日期: 2013年10月30日 实验成绩: 批改教师: 批改时间: 实验3 堆栈和队列一、实验目的和要求(1)掌握应用栈解决问题的方法。(2)掌握利用栈进行表达式求和的算法。(3)掌握队列的存储结构及基本操作实现,并能在相应的应用问题中正确选用它们。二、实验仪器和

19、设备Turbo C 2.0三、实验内容与过程(含程序清单及流程图)1、必做题(1) 判断一个算术表达式中开括号和闭括号是否配对。(2) 测试“汉诺塔”问题。(3) 假设称正读和反读都相同的字符序列为”回文”,试写一个算法判别读入的一个以为结束符的字符序列是否是“回文”。2、选做题在顺序存储结构上实现输出受限的双端循环队列的入列和出列算法。设每个元素表示一个待处理的作业,元素值表示作业的预计时间。入队列采取简化的短作业优先原则,若一个新提交的作业的预计执行时间小于队头和队尾作业的平均时间,则插入在队头,否则插入在队尾。程序清单:1、typedef int datatype;#define M 1

20、00typedef struct char dataM; int top; seqstack;main() char strM; int result=0,i=0; seqstack s; s.top=0; gets(str); while(stri!=0) if(stri=() s.top+; s.datas.top=(; if(stri=) if(s.top=0) result=1; break; else s.top-; i+; if(result=0 & s.top=0) printf(Match!n); else if(result=1) printf(Missing left!n)

21、; else if(s.top0) printf(Missing right!n);2、#includevoid hanoi(int n,char a,char b,char c) if(n=1) printf(n Move disk %d from pile %c to pile %c,n,a,c); else hanoi(n-1,a,c,b); printf(n Move disk %d from pile %c to pile %c,n,a,c); hanoi(n-1,b,a,c); void main() int n; clrscr(); printf(n Please enter t

22、he number of disks to be moved:); scanf(%d,&n); hanoi(n,A,B,C);3、#include#define M 100typedef struct char dataM; int top;seqstack;main() char strM; int i=0,n; seqstack s; s.top=0; gets(str); while(stri!=) i+; if(i=1) printf(Yesn); return; n=i; for(i=0;in/2;i+) s.top+; s.datas.top=stri; i=i-1; if(n%2

23、=0) i+; else i=i+2; while(in & s.datas.top=stri) i+; s.top-; if(i=n) printf(Yesn); else printf(Non);四、实验结果与分析(程序运行结果及其分析)1、输入:(a)输出结果:Match!输入:(a输出结果:Missing right!输入:a)输出结果:Missing left!2、输入:3 输出结果:Move disk 1 from pile A to pile CMove disk 2 from pile A to pile BMove disk 1 from pile C to pile BMo

24、ve disk 3 from pile A to pile CMove disk 1 from pile B to pile AMove disk 2 from pile B to pile CMove disk 1 from pile A to pile C3、输入:qwewq 输出结果:Yes 输入:qwerewr 输出结果No五、实验体会(遇到问题及解决办法,编程后的心得体会)遇到问题:在本章栈和队列中编程,有许多的if语句,编写时一不小心就会少加一个花括号,以致编写不成功。在本章汉诺塔问题中,使用了栈以及函数的递归,这其中的过程一直不是很了解,在经过老师的讲解后,理解了大致过程。实验体

25、会:递归函数是编程中经常会用到的一种函数,它可以实现许多我们在平时言语和解释上解决不了的问题,我们需要理解并且可以熟练的使用它,这对我们之后的编程会有很大的帮助。而汉诺塔利用栈是一种很经典的递归的算法,这让我们理解栈和递归。实验项目名称: 串 实验学时: 2 同组学生姓名: 实验地点: 工科楼A205实验日期: 2013年11月6日 实验成绩: 批改教师: 批改时间: 实验4 串一、实验目的和要求掌握串的存储及应用。二、实验仪器和设备Turbo C 2.0三、实验内容与过程(含程序清单及流程图)1、必做题(1) 编写输出字符串s中值等于字符ch的第一个字符的函数,并用主函数测试结果。(2) 编

26、写输出字符串s中值等于字符ch的所有字符的函数,并用主函数测试结果。解题思路:可以将第一题程序改进成一个子函数,在本题中循环调用。(3) 设字符串采用单字符的链式存储结构,编程删除串s从位置i开始长度为k的子串。2、选做题假设以链结构表示串,编写算法实现将串S插入到串T中某个字符之后,若串T中不存在这个字符,则将串S联接在串T的末尾。提示:为提高程序的通用性,插入位置字符应设计为从键盘输入。程序清单:1、#define maxsize 100typedef struct char chmaxsize; int curlen;seqstring;main() int i; char ch; se

27、qstring s=asdfghg,6; for(i=0;is.curlen;i+) printf(%c,s.chi); printf(nPlease input aa character ch:); scanf(%c,&ch); for(i=0;i=s.curlen) printf(Not find!n);2、#define maxsize 100typedef struct char chmaxsize; int curlen;seqstring;main() int i,flag=0; char ch; seqstring s=abadeag,6; for(i=0;is.curlen;i+) printf(%c,s.chi); printf(nPlease input aa character ch:); scanf(%c,&ch); for(i=0;is.curlen;i+) if(s.chi=ch) printf(ch=s.ch%d=%cn,i,s.chi); flag+; if(flag=0) printf(Not find!n);3、#include#includetypedef struct linknode char data; struct linknode *next;linkstring;main() linkstring *head,*s,*r,

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1