资源描述:
《数据结构图实验.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、学生实验报告课程名称______数据结构_____实验日期___2011___年_12__月_20__日学生姓名xxx学号1004061020所在班级计102实验名称Project7:TraversalsandApplicationsofGraph实验地点X-109同组人员无实验仪器(软件、硬件环境)Xp系统,vc++6.0实验目的(要求)1.ProblemGivenadirectedgraph(seeFigure2),usetheadjacencylistmethodtorepresentit,andoutputthe
2、sequenceofvertexnamesgettingfromDepth-FirstSearchandBreadth-FirstSearch.AndGivenasourcev0,Determineashortestpathtoeachv∈V(G){v0}andoutputthem.2.InputandOutputDemandInput:thenumberofvertex,thenumberofedge,alledges(Vi,Vj)anditsweightinagraph.Output:(1).printthegra
3、ph.(2).printthesequenceofvertexnamesgettingfromDepth-FirstSearch.(3).printthesequenceofvertexnamesgettingfromBreadth-FirstSearch.Forexample(SeeFigure1):Input:611//indicatethegraphincludingsixvertexesandelevenedges.0150//indicateanedgefromV0toV1.021004451215141020
4、202315312034354330533Figure2Output:0:1241:242:033:144:35:3ThesequenceofvertexnamesgettingfromDepth-FirstSearch(from‘V1’):V1V2V0V4V3V5ThesequenceofvertexnamesgettingfromBreadth-FirstSearch(from‘V1’):V1V2V4V0V3V5Shortestpathsfromv0toeachvertexareV0toV145V0toV210V0t
5、oV325V0toV445V0toV51000(“1000”meansnopath.)3.Stepsandrestrictconditions:Step1.ImplementDepth-FirstSearchAlgorithm;Step2.ImplementQueueADTrepresentedbycircularqueue,whichhassevenbasicoperations:CreateQueue,IsEmpty,DisposeQueue,MakeEmpty,EnQueue,Front,DeQueue.Theel
6、ementtypeispointerofnode;Step3.ImplementBreadth-FirstSearchAlgorithm;Step4.Writeafunctiontodetermineashortestpathfromvitoeachv∈V(G){vi}.Note:Yourprogrammustreadfromafile“input.txt”andwritetoafile“output.txt”inthecurrentdirectory.实验内容和步骤(硬件类为:原理、主要步骤、电路原理图等)(软件类为
7、:数据结构、算法、主要步骤、界面等)本实验先要了解清楚图的建立,三种邻接矩阵,邻接表,邻接多层表这些表达方式。一开时因为建图的问题导致后来程序的从写,浪费了很多时间,以后要多花带点时间了解清楚实验的要求。这是结构体structGNode{intiVertex;inta;structGNode*pNextChild;};structIntQueue{intIntArray[MAX_SIZE];intiFront,iRear;};Gnode作为结构体指针,在放到数组中,形成结构体数组。这样方便栈,队的操作。这是邻接表的建立/
8、/添加一条从iCurVertex到iLinkedVertex的边intInsertEdge(structGNode*g[MAX_VERTICES],intiCurVertex,intiLinkedVertex,intb){structGNode*pNode;pNode=(structGNode*)malloc(siz