数据结构试验图的建立与运算

上传人:工**** 文档编号:508057391 上传时间:2023-01-23 格式:DOCX 页数:9 大小:103.64KB
返回 下载 相关 举报
数据结构试验图的建立与运算_第1页
第1页 / 共9页
数据结构试验图的建立与运算_第2页
第2页 / 共9页
数据结构试验图的建立与运算_第3页
第3页 / 共9页
数据结构试验图的建立与运算_第4页
第4页 / 共9页
数据结构试验图的建立与运算_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《数据结构试验图的建立与运算》由会员分享,可在线阅读,更多相关《数据结构试验图的建立与运算(9页珍藏版)》请在金锄头文库上搜索。

1、实验报告实验名称:数据结构实验五实验内容:图的建立与运算实验仪器:计算机学院:计算机学院班级:B软件工程学号:XXXX姓名: XXX成绩:指导教师:XXX实验五 图的建立与运算问题描述建立无向非连通图的邻接表存储结构,要求顶点个数不少于 15 个。用DFS及BFS对此邻接表进行遍历,打印出两种遍历的顶点访问顺序。给定图中任意两个顶点 v1 和 v2 及整数 k , 判断是否存在从v1 到 v2 的路径长度为 k 的简单路径,若有打印出路径上的顶点序列(要求路径上不含回路) 。进一步:找出从v1 到v2 的所有路径长度为 k 的简单路径。 (简单路径:顶点序列中不含重现的顶点的路径。 )程序代码

2、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 =

3、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,dre

4、amse 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 oftheCPCC

5、entralCommittee,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 v

6、elopment 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 != NU

7、LL )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 curren

8、t)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 socialismwit

9、henationofthe 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,

10、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

11、 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

12、-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

13、 = 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 gre

14、atrevivalisChinesemodern 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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号