数据结构上机实验报告.doc
![资源得分’ 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)
《数据结构上机实验报告.doc》由会员分享,可在线阅读,更多相关《数据结构上机实验报告.doc(41页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、!-数据结构上机实验报告 学 院:电子工程学院 专 业:信息对抗技术 姓 名: 学 号: 教 师:饶 鲜 日 期:目 录实验一 线性表- 2 -一、实验目的- 2 -二、实验代码- 2 -三、实验结果- 8 -四、个人思路- 9 -实验二 栈和队列- 9 -一、实验目的- 9 -二、实验代码- 10 -三、实验结果- 15 -四、个人思路- 16 -实验三 数组- 16 -一、实验目的- 16 -二、实验代码- 16 -三、实验结果- 18 -四、个人思路- 18 -实验四 树- 18 -一、实验目的- 18 -二、实验代码- 19 -三、实验结果- 24 -四、个人思路- 25 -!-实验一
2、 线性表一、实验目的1 熟悉线性表的顺序和链式存储结构2 掌握线性表的基本运算3 能够利用线性表的基本运算完成线性表应用的运算二、实验代码1 设有一个线性表E=e1, e2, , en-1, en,设计一个算法,将线性表逆置,即使元素排列次序颠倒过来,成为逆线性表E= en, en-1 , , e2 , e1 ,要求逆线性表占用原线性表空间,并且用顺序表和单链表两种方法表示,分别用两个程序来完成。(文件夹:习题1)代码:单链表代码:/单链表逆置主文件.cpp#include#include#include单链表结构类型定义.h#include建立单链表.h#include输出单链表.h#inc
3、lude单链表逆置.hvoid main()linklist*head;creat(head);print(head);invert(head);/调用单链表逆置的函数print(head);/单链表结构类型定义.htypedef char datatype;typedef struct nodedatatype data;struct node *next;linklist;/建立单链表.hvoid creat(linklist*&head)/采用尾插法建立具有结点的单链表char ch;linklist *s,*r;head=new linklist;r=head;while(ch=get
4、char()!=*)s=new linklist;s-data=ch;r-next=s;r=s;r-next=NULL;/输出单链表.hvoid print(linklist *head)linklist*p=head-next;while(p!=NULL)coutdatanext;coutnext; q=p-next; while(q!=NULL) r=q-next; q-next=p; p=q; q=r; head-next-next=NULL; head-next=p; 单链表结果截图见下方实验结果。顺序表代码:/顺序表逆置主文件.cpp#include#include#include顺
5、序表结构类型定义.h#include建立顺序表.h#include输出顺序表.h#include顺序表逆置.hvoid main()sequenlist*L;creat(L);print(L);invert(L);/调用顺序表逆值的函数print(L);/顺序表的结构类型定义.htypedef char datatype;const int maxsize=1024;typedef struct datatype datamaxsize; int last;sequenlist;/建立顺序表.hvoid creat(sequenlist*&L)L=new sequenlist;L-last=0
6、;char ch;while(ch=getchar()!=*)L-dataL-last=ch;L-last+;/输出顺序表.hvoid print(sequenlist*L)for(int i=0;ilast;i+)coutdatai ;coutlast-1; while(idatai; L-datai=L-dataj; L-dataj=mid; i+;j-; 顺序表实验截图见下方实验结果。2 已知由不具有头结点的单链表表示的线性表中,含有三类字符的数据元素(字母、数字和其他字符),试编写算法构造三个以循环链表表示的线性表,使每个表中只含有同一类的字符,且利用原表中的结点空间,头结点可另辟空间
7、。(文件夹:习题2)代码:/分解单链表主程序文件.cpp#include#include#include单链表结构类型定义.h#include建立单链表.h#include输出单链表.h#include输出循环链表.h#include在循环链表中插入.h#include分解单链表.hvoid main() linklist *head,*letter,*digit,*other; creat(head); print1(head); letter=new linklist; letter-next=letter; digit=new linklist; digit-next=digit; ot
8、her=new linklist; other-next=other; resolve(head,letter,digit,other);/调用分解单链表的函数 print2(letter); print2(digit); print2(other);/单链表结构类型定义typedef char datatype;typedef struct node datatype data; struct node *next;linklist;void creat(linklist*&head)/建立单链表 datatype x; linklist *s,*r; head=new linklist;
9、r=head; cinx; while(x!=$) s=new linklist; s-data=x; r-next=s; r=s; cinx; r-next=NULL;void print1(linklist*head)/输出单链表 linklist *p=head-next; while(p!=NULL) coutdata; p=p-next; coutnext; while(p!=head) coutdata; p=p-next; coutnext!=h) q=q-next; q-next=p; p-next=h;/分解单链表.hvoid resolve(linklist* head,l
10、inklist* letter,linklist* digit,linklist* other)linklist* p = head-next,*t;head-next =NULL;while (p!=NULL)t = p; p=p-next;if (t-data =0 & t-data data =a & t-data data =A & t-data quelen=0;队满的条件:sq-quelen=m。(文件夹:习题3)/循环队列入队出队的主程序文件.cpp#include#include#include#include循环队列的结构类型定义.h#include置空队.h#include
11、入队.h#include出队.hvoid main() qu *sq;datatype x, *p;int key;sq=new qu;setnull(sq);do coutkey;switch(key) case 1: coutx;enqueue(sq,x);break;case 2: p=dequeue(sq);if(p!=NULL) cout*pquelen=0) printf(队列为空,请先进行入队操作n);return 0; else temp=(datatype*)malloc(sizeof(datatype); sq-quelen-; *temp=sq-sequ(sq-rear-
12、sq-quelen+m)%m; coutquelen=m) printf(队列已满,请先进行出队操作n); else sq-quelen+; sq-rear=(sq-rear+1)%m; sq-sequsq-rear=x; coutrear=m-1;sq-quelen=0;实验截图见下方实验结果。2. 设单链表中存放有n个字符,试编写算法,判断该字符串是否有中心对称的关系,例如xyzzyx是中心对称的字符串。(提示:将单链表中的一半字符先依次进栈,然后依次出栈与单链表中的另一半字符进行比较。)(文件夹:习题4)/判字符串中心对称的主程序文件.cpp#include#include单链表顺序栈结
13、构类型定义.h#include置栈空.h#include求单链表长度.h#include输出单链表.h#include建立单链表.h#include顺序栈入栈.h#include顺序栈出栈.h#include判字符串是否中心对称.h void main()linklist *head;stack *s;datatypestr80;cinstr;creat(head,str);printlink(head);setnull(s);if(symmetry(head,s) cout字符串str中心对称n;else cout字符串strdata=*p;r-next=s; r=s;p+; r-next=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 上机 实验 试验 报告 讲演 呈文
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内