《数据结构》实践考核报告

上传人:夏** 文档编号:469747409 上传时间:2023-10-26 格式:DOC 页数:22 大小:139.50KB
返回 下载 相关 举报
《数据结构》实践考核报告_第1页
第1页 / 共22页
《数据结构》实践考核报告_第2页
第2页 / 共22页
《数据结构》实践考核报告_第3页
第3页 / 共22页
《数据结构》实践考核报告_第4页
第4页 / 共22页
《数据结构》实践考核报告_第5页
第5页 / 共22页
点击查看更多>>
资源描述

《《数据结构》实践考核报告》由会员分享,可在线阅读,更多相关《《数据结构》实践考核报告(22页珍藏版)》请在金锄头文库上搜索。

1、数据结构实践考核报告专业: 计算机及应用 准考证号: 姓名: 考点: 西安电子科技大学考试时间: 2009-5-25一、 实验目的上机考核实践考核检测对数据结构该课程掌握的程度,消化课程内容,加深理解数据结构的基础概念、基本理论和基本方法。二、 实验环境1. 硬件:CPU P4 2.4G内存:256M硬盘:40.G2. 软件: VC+三、 实验考核内容单元一:线形数据结构上的基本运算描述及实现。(1)顺序表上基本算法的运算描述及实现。#define ListSize 100typedef int DataType;typedef structDataType dataListSize;int

2、length;SepList;void Set(SepList *L)L-length=0;void InsertList(SepList *L,DataType x,int i)int j;if(iL-length+1) Error(position error); if(L-length=ListSize) Error(overflow); for(j=L-length-1;i=i-1;j-) L-dataj+1=L-dataj; L-datai-1=x; L-length+; void Covers(SepList *L)int i;DataType temp;for(i=0;ileng

3、th/2;i+)temp=L-datai;L-datai=L-dataL-length-i-1;L-dataL-length-i-1=temp;void Out(SepList *L)int i;for(i=0;idatai);main()int x,i,y=0;char ch=ASeqlist *L;set(L);while(y!=5)printf(choice num:n 1:is create list:n 2:is insert list:n)printf( 3:is delete list:n 4:is Covers list:n);printf( 5:is end:n);scanf

4、(%d,&y);if(y=1)printf(creat a list and input init data:)scanf(%d,&y);L-length=x;for(i=0;idatai=x;printf(list is:);Out(L);printf(n);else if(y=2)printf(input data insert and position i:);scanf(%d,&x); scanf(%d,&i);InsertList(L,x,i);Out(L);printf(n);else if (y=3)printf(input delete position:);scanf(%d,

5、&x);DeleteList(L,x);Out(L);printf(n);else if (y=4)printf(convers is:);Convers(L);Out(L);else if (y=5) exit(0);scanf(%d,&y);(2)单链表上基本算法的运算描述及实现。#include stdio.h#include stdlib.h#define null 0struct stu char data; struct stu *next; ;main() /*主函数*/int x,x1; char ch; struct stu *head,*p,*s,*q,*h,*z; pri

6、ntf(现在开始建立链表.请输入字符:n); /*开始建立链表*/ head=(struct stu *)malloc(sizeof(struct stu); p=head; p-next=null; ch=getchar(); while(ch!=n) s=(struct stu *)malloc(sizeof(struct stu); s-data=ch; p-next=s; p=s; p-next=null; ch=getchar(); /*建立后输出*/ printf(建立后的链表为:n ); p=head; output(p-next); p=head;aa: printf(n);p

7、rintf(* * * * * * * * * * * * * * * * * * * * * * * * * * *n);printf(* *n);printf(* *n); printf(* 1.插入 2.删除 *n);printf(* *n);printf(* *n); printf(* 3.逆转 4输出 *n);printf(* *n); printf(* *n);printf(* 其它:退出 *n);printf(* *n);printf(* *n);printf(* * * * * * * * * * * * * * * * * * * * * * * * * * *n);prin

8、tf(n);printf( 请输入您想做的操作的序号:);scanf(%d,&x); /*switch函数*/ switch(x) case 1: printf(请输入你要插入的字符和位置:n); scanf(%s%d,&ch,&x1); insert(p,ch,x1); /*调用insert函数*/ goto aa;break; case 2: printf(请输入你要删除的字符: ); goto aa;scanf(%s,&ch);delete(p,ch);/*调用delete函数*/ break; case 3: printf(逆转后的链表为: ); coverse(p); /*调用cov

9、erse函数*/ goto aa; break; case 4: printf(输出后的链表为:); goto aa;output(p-next);break; default:exit() ; /*调用output函数*/ printf(t谢谢使用!n); /*主函数结束*/ insert(struct stu *p,char ch1,int x) /*insert函数*/ int i,j,k; struct stu *q,*h,*s; q=p-next; h=p; i=2; j=1;while(q) q=q-next; j+; /*j为链表的长度*/q=p-next; if(x=j+1)p

10、rintf(插入位置有错,原链表为:n); else while(x=j+1&inext;h=h-next;i+;s=(struct stu *)malloc(sizeof(struct stu);s-data=ch1;h-next=s;s-next=q; output(p-next); /*输出插入后的链表*/ /*insert函数结束*/ delete(struct stu *p,char ch) /*delete函数开始*/ int k; struct stu *q; q=p; k=0; while(q) while(q-next-data=ch) q-next=q-next-next; q=q-next; k=1; printf(删除后的链表为:); if(k=0)printf(没有找到你要删除的字符!n); output(p-next); /*delete函数结束*/ coverse(struct stu *p) /*coverse函数开始*/ struct stu *q,*head

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号