资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
实验报告实验名称:数据结构实验五实验内容:图的建立与运算实验仪器:计算机学院:计算机学院班级:B软件工程学号:XXXX姓名: XXX成绩:指导教师:XXX实验五 图的建立与运算问题描述建立无向非连通图的邻接表存储结构,要求顶点个数不少于 15 个。用DFS及BFS对此邻接表进行遍历,打印出两种遍历的顶点访问顺序。给定图中任意两个顶点 v1 和 v2 及整数 k , 判断是否存在从v1 到 v2 的路径长度为 k 的简单路径,若有打印出路径上的顶点序列(要求路径上不含回路) 。进一步:找出从v1 到v2 的所有路径长度为 k 的简单路径。 (简单路径:顶点序列中不含重现的顶点的路径。 )程序代码using namespace System;#include stdafx.h#include stdlib.h#include stdio.h#include conio.hstruct nodeint vertex;struct node *nextnode;typedef struct node *graph;struct node head9;int visited9;void creategraph( int node152, int num)graph newnode;graph ptr;int from;int to;int i;for ( i = 0; i vertex = to;newnode-nextnode = NULL;ptr = &(headfrom);while ( ptr-nextnode != NULL )ptr = ptr-nextnode;practiceintheflyingyouth dreoder ntimes.Zhiam achihan one occasi on, GeneralSeamnotonlybee cretaryexpounde d te,and be nefitworl d ped the scie ntificconnotation of Chinepe opl e innovation due itsShihi,dreamse dream,reali zethe Chi nese dream musttakethe road, carryforwardt hespiritandcohe. - L sionofChineseforseforces,graduallyformeof dream,.3. ondeepeni ht.Andpra ctice wit hthe Chi nese dream, reflectstnce the XIGe neralSe cretaryforthe first time toStudyon thehehi storyof thenew sessi on oftheCPCCentralCommittee,andconformstotclosely focus on the developmentof socialihe dev elopmenttrend and the - - - , - -smwith Chinesecharacteripeople hope,embodie 一stics studya nd publicizethespiritofparty 18,tdetermination asthegreatestndcourage. Partyscommon divisorandthehe unwaveringlya dhere tothe de velopment ofsocialism withChi nese chara cteristics,the persiste nce a nd g ood use of Mao Ze-Dongst hought ofsoul.conse nsusofChinesepeople at homea _ II,ptr-nextnode = newnode;void dfs( int current)graph ptr;visitedcurrent = 1;printf( vertex%dn ,current);ptr = headcurrent.nextnode;while ( ptr != NULL )if ( visitedptr-vertex = 0 ) dfs(ptr-vertex);ptr = ptr-nextnode;#define MAXQUEUE 10int queueMAXQUEUE;int front = -1;int rear = -1;int enqueue( int value)if ( rear = MAXQUEUE )return -1;rear+;queuerear = value;int dequeue()if ( front = rear )return -1;front+;return queuefront;void bfs( int current)graph ptr;enqueue(current);visitedcurrent = 1;printf( Vertex%dn ,current); while ( front != rear )current = dequeue();ptr = headcurrent.nextnode;Tosumup,i s divided int o9 main part s:1.wit h regard to persistinga2.with regard tot heChinese dream ofrealizingthegreat rejuvnd developing socialismwithenationofthe Chi nese nation. 18clChi nese chara cteristics.18 sincethe XIOn morethaosi ngsoon,the new Ce ntralcoll ective lea dershioftheroahistori caloriginanddevel opme ntprocess of socialism withXI,GeneralSenese chara cteristics,the road ofsociali smw ith Chi nese cnation oftheChine se nati on,thegreatestesecharacteristicsi s determine dto hav e beecretaryexpoundedthescientificconnotatid,further stre ngtheze the Chinesedredream suita blehav e its pote ntialachievedalism withChinesecharacteristi cs.Chinadream,a strategic thougon deepeni ng reform.18 si ncetheXI. XIGe neralSe cretarysspeech inthi ht.Andpra ctice wit htheChinese dream,refle GeneralSe cretary for the firsttime toStudyon thesregardinclude the 一ctsthehedevel opm ntof socialism wit h Chi nesecharacteristi csstudyandpublihe devel opme nttrend ahe roa d of reform and opebodies the greatestwhile ( ptr != NULL )if ( visitedptr-vertex = 0 )enqueue(ptr-vertex);visitedptr-vertex = 1;printf( Vertex%dn ,ptr-vertex);ptr = ptr-nextnode;void main()graph ptr;int node152 = 1, 7, 7, 1,5, 2, 2, 5,6, 5, 5, 6,1, 3, 3, 1,4, 7, 7, 4,3, 7, 7, 3,5, 9, 9, 5, 5, 5;int i;for ( i = 1; i = 8; i+ )headi.vertex = i;headi.nextnode = NULL;visitedi = 0;creategraph(node,15);printf( 深度优先遍历:n );for ( i = 1; i ,headi.vertex);ptr = headi.nextnode; while ( ptr != NULL )printf( %d ,ptr-vertex);ptr = ptr-nextnode;printf( n );Chine se characteri stics flag sandhig h melody.Thisaspects XIGe neralSecretary ofspe ech main i ncludi ngachieved Chi nese greatrevivalisChinesemodern yilaimostgreatofdream i n12t h session nati onal peoples CongressfirsttimesConfere nceS hang ofspe ech worktodream int oreallyinchieve dChina dreamofvividpracticeintheflyingyouth dre am achi eved Chinadreamnotonlybe nefitpe opl e,and be nefitworl d pe opl e innovation due itsShi,dream suitablehaveitspotentialachieved
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号