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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

级本科数据结构实验指导书.docx

1、级本科数据结构实验指导书数据结构与算法实验指导书实验一 线性表的实验一、实验目的1、掌握用Visual C+6.0上机调试顺序表的基本方法。2、掌握顺序表的基本操作,插入、删除、查找、以及有序顺序表的合并等算法的实现。3、掌握用Visual C+6.0上机调试单链表的基本方法。4、掌握单链表的插入、删除、查找、求表长以及有序单链表的合并算法的实现。5、进一步掌握循环单链表和双链表的插入、删除、查找算法的实现。二、实验内容(一)完成下列程序,该程序生成一个如表1所示的顺序表,并在第2个位置插入如表2所示的数据元素,删除在第3个位置的数据元素,显示顺序表的每个元素。要求生成顺序表时,从键盘上读取数

2、据元素,用顺序存储结构实现存储。表1学号姓名性别年龄2013001张珊女192013002李思女192013004王强男202013005赵括男212013006刘刚男20表22013003陈琪女19typedef struct DataType listMaxSize; int size; SeqList;void ListInitiate(SeqList *L) L-size = 0; /*定义初始数据元素个数*/ int ListLength(SeqList L) return L.size;int ListInsert(SeqList *L, int i, DataType x) in

3、t j; for(j = L-size; j i; j-) L-listj = L-listj-1; L-listi = x; /*插入x*/ L-size +; /*元素个数加1*/ return 1; int ListDelete(SeqList *L, int i, DataType *x) int j; *x = L-listi; /*保存删除的元素到x中*/ for(j = i +1; j size-1; j+) L-listj-1 = L-listj; L-size-; /*数据元素个数减1*/ return 1;int ListGet(SeqList L, int i, Data

4、Type *x) if(i L.size-1) printf(参数i不合法! n); return 0; else *x = L.listi; return 1; (二)已知顺序表la和lb中的数据元素按非递减有序排列,将la和lb表中的数据元素,合并成为一个新的顺序表lc,要求 lc中的数据元素仍按非递减有序排列,并且不破坏la和lb表。(三)完成下列程序,该程序构建如表3所示的带头结点的单链表h,在单链表h中第3个数据元素之前插入如表4所示的数据元素,删除第4个数据元素。要求生成单链表时,从键盘上读取数据元素,用链式存储结构实现存储。表3员工编号姓名性别职位001张珊女文员002李思女销售

5、员004王强男经理005赵括男秘书006刘刚男文员表42013003陈琪女19typedef struct Node DataType data; struct Node *next; SLNode;void ListInitiate(SLNode *head) *head = (SLNode *)malloc(sizeof(SLNode); (*head)-next = NULL; int ListLength(SLNode *head) SLNode *p = head; int size = 0; while(p-next != NULL) p = p-next; size +; ret

6、urn size;int ListInsert(SLNode *head, int i, DataType x) SLNode *p, *q; int j; p = head; j = -1; while(p-next != NULL & j next; j+; if(j != i - 1) printf(“插入位置参数错!”); return 0; q = (SLNode *)malloc(sizeof(SLNode); q-data = x; q-next = p-next; p-next = q; return 1;int ListDelete(SLNode *head, int i,

7、DataType *x) SLNode *p, *s; int j; p = head; j = -1; while(p-next != NULL & p-next-next!= NULL & j next; j+; if(j != i - 1) printf(“插入位置参数错!”); return 0; s = p-next; *x = s-data; p-next = p-next-next; free(s); return 1; int ListGet(SLNode *head, int i, DataType *x) SLNode *p; int j; p = head; j = -1

8、; while(p-next != NULL & j next; j+; if(j != i) printf(“取元素位置参数错!”); return 0; *x = p-data; return 1; void Destroy(SLNode *head) SLNode *p, *p1; p = *head; while(p != NULL) p1 = p; p = p-next; free(p1); *head = NULL;(四)已知单链表la和lb中的数据元素按非递减有序排列,将la和lb中的数据元素,合并为一个新的单链表lc,lc中的数据元素仍按非递减有序排列。要求不破坏la表和lb表

9、的结构。(五) 约瑟夫环程序:设有N个人围坐一圈,现从某个人开始报数,数到M的人出列,接着从出列的下一个人开始重新报数,数到M的人以出列,如此下去,直到所有人都出列为此。试设计确定他们的出列次序序列的程序。要求选择单向循环链表作为存储结构模拟整个过程,并依次输出列的各人的编号。如 n=8, m=4 时,若从第一个人, 设每个人的编号依次为 1,2,3,开始报数,则得到的出列次序为4,8,5,2,1,3,7,6,实验二 栈、队列的实现及应用一、实验目的1、掌握栈和队列的顺序存储结构和链式存储结构,以便在实际背景下灵活运用。2、掌握栈和队列的特点,即先进后出与先进先出的原则。3、掌握栈和队列的基本

10、操作实现方法。二、实验内容(一)完成下列程序,该程序实现栈的顺序存储结构,构建顺序栈(栈中的元素依次为R,S,Y,F,C,T),依次进行进栈和出栈操作,判断栈空和栈满操作,返回栈顶元素操作。要求生成顺序栈时,从键盘上读取数据元素。typedef struct DataType stackMaxStackSize; int top; SeqStack;void StackInitiate(SeqStack *S) S-top = 0; int StackNotEmpty(SeqStack S) if(S.top top = MaxStackSize) printf(堆栈已满无法插入! n); r

11、eturn 0; else S-stackS-top = x; S-top +; return 1; int StackPop(SeqStack *S, DataType *d) if(S-top top -;*d = S-stackS-top; return 1; int StackTop(SeqStack S, DataType *d) if(S.top next = NULL; int StackNotEmpty(LSNode *head) if(head-next = NULL) return 0; else return 1;int StackPush(LSNode *head, D

12、ataType x) LSNode *p; p = (LSNode *)malloc(sizeof(LSNode) ; p-data = x; p-next = head-next; head-next = p; return 1;int StackPop(LSNode *head, DataType *d) LSNode *p = head-next; if(p = NULL) printf(堆栈已空出错!); return 0; head-next = p-next; *d = p-data; free(p); return 1;int StackTop(LSNode *head, Dat

13、aType *d) LSNode *p = head-next; if(p = NULL) printf(堆栈已空出错!); return 0; *d = p-data; return 1;void Destroy(LSNode *head) LSNode *p, *p1; p = head; while(p != NULL) p1 = p; p = p-next; free(p1); (三)利用顺序栈实现数制转换,输入十进制整数,分别将其转换为八进制数和二进制数。(四)完成下列程序,该程序实现循环队列的存储和基本操作,构建循环队列(队列中的元素依次为John,Mary,Linda,Mike,

14、Paul),依次进行判断队列是否为空和满操作、入队和出队操作、取得队首元素操作。typedef struct DataType queueMaxQueueSize; int rear; int front; int count; SeqCQueue;void QueueInitiate(SeqCQueue *Q) Q-rear = 0; Q-front = 0; Q-count = 0;int QueueNotEmpty(SeqCQueue Q) if(Q.count != 0) return 1; else return 0;int QueueAppend(SeqCQueue *Q, Dat

15、aType x) if(Q-count 0 & Q-rear = Q-front) printf(队列已满无法插入! n); return 0; else Q-queueQ-rear = x; Q-rear = (Q-rear + 1) % MaxQueueSize; Q-count+; return 1; int QueueDelete(SeqCQueue *Q, DataType *d) if(Q-count = 0) printf(队列已空无数据元素出队列! n); return 0; else *d = Q-queueQ-front; Q-front = (Q-front + 1) %

16、 MaxQueueSize; Q-count-; return 1; int QueueGet(SeqCQueue Q, DataType *d) if(Q.count = 0) printf(队列已空无数据元素可取! n); return 0; else *d = Q.queueQ.front; return 1; 实验三 二叉树的操作及应用一、实验目的1、进一步掌握指针变量、动态变量的含义。2、掌握二叉树的结构特性,以及各种存储结构的特点和适用范围。3、掌握用指针类型描述、访问和处理二叉树的运算。二、实验内容(一)完成下列程序,该程序以二叉链表作存储结构,构建如图1所示的二叉树,并依次进行

17、二叉树的前序、中序、后序及层次遍历。图1typedef struct Node DataType data; struct Node *leftChild; struct Node *rightChild;BiTreeNode;/*初始化*/void Initiate(BiTreeNode *root) *root = (BiTreeNode *)malloc(sizeof(BiTreeNode); (*root)-leftChild = NULL; (*root)-rightChild = NULL;void PreOrder(BiTreeNode *t, void Visit(DataTy

18、pe item)/*前序遍历二叉树t,访问操作为Visit()函数*/ if(t != NULL) Visit(t-data); PreOrder(t-leftChild, Visit); PreOrder(t-rightChild, Visit); void InOrder(BiTreeNode *t, void Visit(DataType item) /*中序t */ if(t != NULL) InOrder(t-leftChild, Visit); Visit(t-data); InOrder(t-rightChild, Visit); void PostOrder(BiTreeNo

19、de *t, void Visit(DataType item) /*后序 */ if(t != NULL) PostOrder(t-leftChild, Visit); PostOrder(t-rightChild, Visit); Visit(t-data); (二)完成下列程序,该程序以二叉链表作存储结构,构建如图2所示二叉树,计算二叉树深度、所有结点总数、叶子结点数、双孩子结点个数、单孩子结点个数。图2int BTreeDepth(BiTreeNode * BT) int leftdep,rightdep; if (BT=NULL) return(0); else leftdep=BT

20、reeDepth(BT-leftChild); rightdep=BTreeDepth(BT-rightChild); if (leftdeprightdep) return(leftdep+1); else return(rightdep+1); int nodecount(BiTreeNode * BT) if (BT=NULL) return(0); else return(nodecount(BT- leftChild)+nodecount(BT- rightChild)+1);int leafcount(BiTreeNode * BT) if (BT=NULL) return(0);

21、 else if (BT- leftChild =NULL & BT- rightChild =NULL) return(1); else return(leafcount(BT- leftChild)+leafcount(BT- rightChild);int notleafcount(BiTreeNode * BT) if (BT=NULL) return(0); else if (BT- leftChild =NULL & BT- rightChild =NULL) return(0); else return(notleafcount(BT- leftChild)+notleafcou

22、nt(BT- rightChild)+1);int onesoncount(BiTreeNode * BT) if (BT=NULL) return(0);else if (BT- leftChild =NULL & BT- rightChild!=NULL) | (BT- leftChild!=NULL & BT- rightChild =NULL) return(onesoncount(BT- leftChild)+onesoncount(BT- rightChild)+1); else return(onesoncount(BT- leftChild)+onesoncount(BT- r

23、ightChild); int twosoncount(BiTreeNode * BT) if (BT=NULL) return(0); else if (BT- leftChild =NULL | BT- rightChild =NULL) return(twosoncount(BT- leftChild)+twosoncount(BT- rightChild); else if (BT- leftChild!=NULL & BT- rightChild!=NULL) return(twosoncount(BT- leftChild)+twosoncount(BT- rightChild)+

24、1);(三)用非递归方式遍历图2所示的二叉树(先序、中序或后序),输出遍历序列。实验四 图的操作及应用一、实验目的1、理解图的基本概念及术语。2、掌握图的两种存储结构(邻接矩阵和邻接表)的表示方法。3、熟练掌握图的两种遍历(深度优先搜索遍历和广度优先搜索遍历)的算法思想、步骤,并能列出在两种存储结构上按上述两种遍历算法得到的序列。4、理解最小生成树的概念,能按Prim算法构造最小生成树。二、实现内容(一)完成下列程序,该程序构造如图1所示的图的邻接矩阵存储结构。图1/*邻接矩阵*/typedef struct SeqList Vertices; int edgeMaxVerticesMaxVe

25、rtices; int numOfEdges; AdjMGraph;void Initiate(AdjMGraph *G, int n) int i, j; for(i = 0; i n; i+) for(j = 0; j edgeij = 0; else G-edgeij = MaxWeight; G-numOfEdges = 0; /*边的条数置为0*/ ListInitiate(&G-Vertices); /*顺序表初始化*/void InsertVertex(AdjMGraph *G, DataType vertex) ListInsert(&G-Vertices, G-Vertices.size, vertex);void InsertEdge(AdjMGraph *G, int v1, int v2, int weight) if(v1 G-Vertices.size | v2 G-Vertices.size) printf(参数v1或v2越界出错!n); exit(1); G-edgev1v2 = weight; G-numOfEdges+;typedef struct int row; /行下标 int col; /列下标 int weight; /权值 RowColWeight;void CreatGr

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

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