数据结构图的遍历实验报告.doc
实 验 报 告课程名称 数据结构实验名称 图的遍历姓 名专 业 计算机科学与技术班 级 计算机学 号成绩计算机科学与技术学院实验教学中心2015 年 11 月 20 日哈尔滨理工大学计算机科学与技术学院实验教学中心 实验报告实验项目名称图的遍历 一、实验目的1 深入学习图的遍历原理 ;2 用代码的形式将图的广度优先遍历和深度优先遍历实现;2、实验内容设计程序将图的广度优先遍历和深度优先遍历实现;3、实验原理includeincludeincludeincludeincludeusing namespace std;const int V 500;const int E 500;int EdgeCount;struct Arcint next_arc;int pointint nodeV;哈尔滨理工大学计算机科学与技术学院实验教学中心 实验报告struct Arc arcE;void Addedgeint u,int varcEdgeCount.next_arc nodeu;arcEdgeCount.point v;nodeu EdgeCount;EdgeCount;int queV;int visV;int staV;int k;int front,rear;void bfsfront rear 0;memsetvis,0,sizeofvis;querear 1;vis1 1;stak 1;whilefront rear int cur_node quefront;哈尔滨理工大学计算机科学与技术学院实验教学中心 实验报告int edge;foredge nodecur_node; edge-1; edge arcedge.next_arcifvisarcedge.pointquerear arcedge.point;visarcedge.point 1;stak arcedge.point;void dfsint vvisv 1;printf“d “,v;int edge;foredge nodev; edge-1; edge arcedge.next_arcifvisarcedge.pointdfsarcedge.point;哈尔滨理工大学计算机科学与技术学院实验教学中心 实验报告int mainint n,m;printf“输入节点数和边数n“;whilescanf“dd“,memsetnode,-1,sizeofnode;forint i 0; im; iint u,v;scanf“dd“,Addedgeu,v;k 0;bfs;forint i 0; ik; iprintf“d “,stai;printf“广度优先n“;memsetvis,0,sizeofvis;dfs1;哈尔滨理工大学计算机科学与技术学院实验教学中心 实验报告printf“深度优先n“;return 0;4、图的结构五、实验结果分析哈尔滨理工大学计算机科学与技术学院实验教学中心 实验报告