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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

实验六图基本操作的编程实现.docx

1、实验六 图基本操作的编程实现 实验六 图基本操作的编程实现【实验目的】图基本操作的编程实现要求:图基本操作的编程实现(2学时,验证型),掌握图的建立、遍历、插入、删除等基本操作的编程实现,存储结构可以在顺序结构、链接结构、联合使用多种结构等中任选,也可以全部实现。也鼓励学生利用基本操作进行一些应用的程序设计。【实验性质】验证性实验(学时数:2H)【实验内容】编程对图进行存储(邻接矩阵或邻接表都可以,由学生自由选择),之后可以询问任何两个结点之间是否有通路和路径数。设计一个将图形转成邻接链表的程序。设计一个深度优先搜索法来查找图形的程序。设计一个广度优先搜索法来查找一个图形的程序。鼓励开发出难度

2、更高的程序。【思考问题】1. 图的定义和特性?2. 图的主要存储结构是什么?是独立的某种还是多种数据结构的综合?3. 图的主要遍历思路是哪些?4. 举出图的应用范例?【参考代码】(一)将一个将图转成邻接矩阵的程序/*程序构思:*/*用户输入结点与各个边,再将边转成邻接矩阵。*/#include#define Max 6 /* 定义最大可输入的结点个数 */int GraphMaxMax; /*图形邻接数组 */*=*/*输出邻接矩阵数据=*/*=*/void print_M_Graph() int i,j; printf(Vertice); for (i=0;iMax;i+) printf(%

3、3d,i); printf(n); for(i=0;iMax;i+) printf(%4d ,i); for (j=0;jMax;j+) printf(%3d ); printf(n); /*=*/*以邻接矩阵建立图形=*/*=*/void Create_M_Graph(int Verticel,int Vertice2) GraphVerticelVertice2=1; /* 将矩阵内容设为1 */ /*=*/*主程序=*/*=*/void main() int Source; /*起始顶点*/ int Destination; /*终止顶点*/ int i,j; for (i=0;iMax

4、;i+) for (j=0;j= Max | Destination = Max) /* 出错:超出范围*/ printf (*Error*: out of range! n); else /*调用建立邻接数组 */ Create_M_Graph(Source,Destination); printf(#Graph#n); ; /*调用输出邻接数组数据*/*希望的结果 */*please input the Edges source:0 */*Please input the Edges Destination:4 */*please input the Edges source:1 */*P

5、lease input the Edges Destination:0 */*please input the Edges source:1 */*Please input the Edges Destination:4 */*please input the Edges source:2 */*Please input the Edges Destination:1 */*please input the Edges source:3 */*Please input the Edges Destination:2 */*please input the Edges source:4 */*P

6、lease input the Edges Destination:3 */*please input the Edges source:-1 */*#Graph# */*Vertice 0 1 2 3 4 5 */* 0 0 0 0 0 1 0 */ /* 1 1 0 0 0 1 0 */ /* 2 0 1 0 0 0 0 */ /* 3 0 0 1 0 0 0 */ /* 4 0 0 0 1 0 0 */ /* 5 0 0 0 0 0 0 */(二) 将一个将图转成邻接表的程序/*程序构思:*/*用户输入结点与各个边,再将边转成邻接链表。*/#include#include #define

7、 vertexnum 6 /* 定义最大可输入的结点个数 */typedef struct node /*定义图形的顶点结构 */ int vertex; struct node *next;Graph;Graph headvertexnum;/*=*/*以邻接链表建立图形=*/*=*/void Create_l_Graph(int Vertex1,int Vertex2) Graph *searchP; /* 结点声明 */ Graph *New; /* 新结点声明 */ New = (Graph *) malloc(sizeof(struct node); if (New!= NULL )

8、 New -vertex = ; New -next = NULL; searchP = &(headVertex1); while ( searchP-next != NULL) ; searchP-next = New; /*=*/*输出邻接链表的数据=*/*=*/void print_l_graph(struct node *head) Graph *searchP; searchP = head-next; while ( searchP != NULL ) printf(%d,searchP-vertex); searchP=searchP-next; printf(n);/*=*/

9、*主程序=*/*=*/void main() int Source; /*起始顶点*/ int Destination; /*终止顶点*/ int i,j; for (i=0;i= vertexnum | Destination = vertexnum) /* 出错:超出范围*/ printf (*Error*: out of range! n); else /*调用建立邻接链表 */ Create_l_Graph(Source,Destination); printf(#Graph#n); for (i=0;i=vertexnum;i+) printf(vertex%d:,i); print

10、_l_graph(&headi); /*调用输出邻接链表数据*/ /*希望的结果 */*please input the Edges source:2 */*Please input the Edges Destination:1 */*please input the Edges source:2 */*Please input the Edges Destination:3 */*please input the Edges source:3 */*Please input the Edges Destination:4 */*please input the Edges source:4 */*Please input the

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

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