2023年数据结构实验报告3.docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2023年数据结构实验报告3.docx》由会员分享,可在线阅读,更多相关《2023年数据结构实验报告3.docx(26页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、数据结构实验报告学号:08055140班级:计算机86姓名: 邓凯提交日期:09 12 1 6#include#i n clud e typedef s t ru c t BN o de(char d a ta;s tru c t BNo d e * 1 ch i Id;st r u ct BNo d e *rc h ild; BTNod e ;1 y p edef BTNode *BinTre e ;v o id C re a te B in T r ee(Bi n Tree *ro o t)/以先序来建立二叉树(char c h ;c h=get c h a r();i f (ch=) 空
2、格*root=NULL; / /建立空二叉树else(*r o ot= (BTN o de*)m a Hoc ( s i z e o f( B TNod e );开辟空间,生成节 点(* r oot)-dat a =c h ;C r e a te B i n T re e (& (*root)-lch i Id);Create B i nTr e e (&(*ro o t ) rc h i 1 d);)v o i d P reO r der(B i nT r ee r o o t ) 先序遍历if (roo t !=NULL)p rint f (,% c , r o o t -da t a);
3、P r e Or d er(ro o t1 c hild );Pre Order(roo t- r chil d );1)void InO r der(Bi n T r e e root)中序遍历i f(ro o i! =NULL)(P reOrd e r(root-l c hild);p rint f (H% c r o o t - d a t a );P r eOrder(root-rchild);)v o id PostOrder( B inTree r oot) / / 后序遍历if ( root!=NULL)(P reOrde r (ro o t- 1 c hild);P re 0
4、r d er( r oot- r c h i 1 d );)printf(%cM, r oot-d a t a);) void mai n ()B in T ree r o o t ;Crea t e B inTree(&r o o t); printf (先序遍历:);PreOrder (root);P r intfCn); printf(中序遍历:);InOrde r (r o o t); printf ( * n);printf(后序遍历:);Post Order(root);printf(n);输入 ab#c#运营结果o t y e k y c c a n b a c a abb c
5、: - : ses ab先中后pro t y e k y c c a n b a c a abb c : - : ses ab先中后prcontinue输入:ab c # # d c#g#f# #输入:ab c # # d c#g#f# #运营结果:abc de g f 先序:abcdegF 中序:bcdegf a 后序:bcdegFaPress any key to continue输入:ab c #dc# # f#i#g# h j # # #运营结果:labc de f i g hj 先序:abc de f ighj 中住:be de F iaghj 后序:bedef ighjaPress
6、 any key to continue六、上机总结课上的速度飞快,还没来得及看书,一章就过去了。现在听课更还是像以前同 样,云里雾里,都快成仙了,但是有些时候还是能听懂,但总也听不完全,因此做这 样的实验真可谓是难啊,先得看上半天的书,然后再在网上看有没有类似的程序, 忙得不可开交,好不容易找到个,编辑器通但是,只是一个错误却半天也找不到, 哎,何苦呢,与其如此还不如自己写,浪费时间,却什么也没学到。这个程序我又 在网上看,看到底怎么个写法,写了半天最后还得请隔壁宿舍的同学帮忙调试,大半天弄不好。但是,还算是搞出来了,这样简朴的一个程序,却也难倒了我, 哎,前路多艰,我将努力学习。七、参考资
7、料清华大学出版社清华大学出版社西安交大出版社1 .数据结构(C语言版)2 .数据结构习题集3 . C+ +面向对象程序设计第三次二、上机实习题目对于十个输入的整形数据进行快速排序,并按照从小到大的顺序输出排序后 结果并测试以下数据:(一)、098 7 6 5 4 3 2 1(二)、12, 23, 89, 9 0 J8, 76,4 5 ,34,43,60(三)、1 , 12 3,1 2,45,8 76, 345,24, 3 7,0,876三组数据。二、相关知识或技术(相应DS部分)C语言,C+的一些基本知识,快速排序的算法以及应用之类的知识。五、算法及数据结构设计(算法设计)快速排序中的一趟:i
8、 nt par tition(i n t a ,in t 1 o w, int h i gh)1 n t pivotk e y;pi v otk e y= a low;whi 1 e(lo wh i gh)w h ile( 1 o w=pivo t key) high;a low =a h ig h ;whil e (1 o w h igh&a 1 ow=piv o t k ey)+ +low;ah i gh=alow;Ia 1 o w=p i v otk e y ;r e turn low;)快速排序的递归形式:vo i d qs o rt ( int a,int low,int hi g
9、h)int p ivot 1 oc;i f(low h i g h)p i v o tlo c = p a rt i t i o n(a, low,hi g h); /一趟排序结果的调用q s ort(a, low,p i v o tloc-1);q s o r t (a,p i v o t 1 o c+ 1, high);四、Mi c r osof t vs6.0五、源程序(带注释或说明)、运营结果(数据或屏幕显示、结 果分析、讨论T(n)i nc 1 u d e stdio. h # inc 1 ude std 1 ib. h# d efi n e N 10i n c lu d e io
10、s t r earn, h int p a rtit i o n( i nt a,int 1 ow, i nt h i gh) /快速排序中的一趟 i nt pivotkey;p i votkey= a low;w h ile(l o whig h )while(low= p i vol k ey)-high;alow=a high;while(lowhigh&a 1 ow=p i vo t key)+ 1 ow;a h i gh =alow;)alow=pivotke y ;retu r n 1 ow;)void q s o r t(int a, in t 1 o w, i n t high
11、) /快速排序的递归形式 int p ivotlo c ;if(l o whigh)pivot! o c =p a r tit i on(a, low, high);一趟排序结果的调用qsort( a ,low, p i v o tlo c -1);q s o rt(a,p i v o t 1 oc+ 1 ,high);)V o id ini t (i o t a )输入要拍的数据int i;cout”请输入将要排序的十个数字“Vendl;f or(i=0;ia i ;)v o i d m a i n() (o int aN, i ;o i n it(a);。 q s ort( a ,0,N)
12、;。print。排序后的结果n);for( i =1; i V=N;i+)输出排序后的数据 printf(n% d , a i- 1 );if(i%10=0)。 pr i ntf(n n );pr i n t f (”nn );)测试数据1 .输入:0 98 76 5 4 3 2 1运营结果:请输入将要排序的十个数字0987654321排序后的结果0123456789Press any key to continue.输入:12, 23,89, 9 0 , 78, 7 6,45, 3 4,4 3,60运营结果:情输入将要排序的十个数字12 23 89 90 78 76 45 34 43 60P
13、ress any key to continue.2 .输入:1, 1 23,12, 45,8 7 6,345,24, 3 7, 0, 876运营结果:请输入将要排序的十个数字1 123 12 45 876 345 24 37 0 876Press any key to continue六、上机总结课终于上完了,但这门课还没有结束,除了实验尚有考试,迄今为止,还是很 不懂,费了大半天的功夫,也只能做出这类的极其简朴的程序,还是多半用的过去 的知识,真是惭愧啊。但是总还算是有些收获,至少这个程序所运用的快速排序 还是学会了。也只有慢慢来了,前路多艰,也不仅仅是数据结构这门课程,其实 好多事情也正
14、如数据结构这门课程,难,但是不得不学,对于计算机的同学,应当是 不得不学会。选择了计算机就无可避免的选择了数据结构,选择了人生也就选择 了努力与奋斗,这算是这次实验的一点心得吧。七、参考资料清华大学出版社清华大学出版社西安交大出版社1 .数据结构(C语言版)2 .数据结构习题集3 .C+面向对象程序设计第一次一、上机实习题目运用链表实现数据的排序,并检测:(一)、1 2、21、34、56、23、3 6、87、13、98 7。(二)、9、2、4、1、5、3、6、7、8、12、13、11、10。(三)、2 34、162、289、99 9、435、90三组数据。二、相关知识或技术(相应DS部分)C+
15、的一些基本知识,以及链表的创建以及应用之类的知识。三、算法及数据结构设计(算法设计)void sort(Lnod e *L) / /链表中元素按递增排序Ln o de*p, * q ,*r,*s;i f (L-next! =NULL)p=L-next-next;L- n ext-n e x t=NULL;wh i le ( p )(q = p;p = p-ne x t;r二 L;第四次三、上机实习题目实现树与二叉树的转化,并测试一组数据。二、相关知识或技术(相应DS部分)c语言,C+的一些基本知识,树、二又树的基本知识。六、算法及数据结构设计(算法设计)void ChangeToBin a r
16、 y(No d e * p Node)(if (pLCh i Id = NULL)re t urn;Node * p L = ne w Nod e ( p LChi 1 d- v al);pNodepLeft = pL;pLChildChang e T o Bi n ary(pN o d e-pLe f t);if(pLCh i 1 d -p R Si b lin g )(Node * pR = new Node (pLChi 1 d-p R S ibling- v al);pNodepRig h t = pR;pLC hild- p RSib 1 ing-Ch a ng e ToBina r
17、 y( p Nod e -pRighl);)四、M icrosof t v s 6.0五、源程序(带注释或说明)、运营结果(数据或屏幕显示、 结果分析、讨论T(n)# i n c 1 u d e u s i ng nam e s p a ce st d ;s tr u c t Node;struct Tre e Node;s tru c t No d e(ch a r v a 1;Nod e * pL e f t ;Nod e * pR i g ht;Node()pLef t = NULL;pRigh t = NULL;)Node(ch a r ch)(v al = ch;pLef t = N
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2023 数据结构 实验 报告
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内