实验六图基本操作的编程实现Word文档格式.docx
- 文档编号:15692490
- 上传时间:2022-11-15
- 格式:DOCX
- 页数:16
- 大小:18.01KB
实验六图基本操作的编程实现Word文档格式.docx
《实验六图基本操作的编程实现Word文档格式.docx》由会员分享,可在线阅读,更多相关《实验六图基本操作的编程实现Word文档格式.docx(16页珍藏版)》请在冰豆网上搜索。
【思考问题】
1.图的定义和特性?
2.图的主要存储结构是什么?
是独立的某种还是多种数据结构的综合?
3.图的主要遍历思路是哪些?
4.举出图的应用范例?
【参考代码】
(一)将一个将图转成邻接矩阵的程序.
/*程序构思:
*/
/*用户输入结点与各个边,再将边转成邻接矩阵。
#include<
stdio.h>
#defineMax6/*定义最大可输入的结点个数*/
intGraph[Max][Max];
/*图形邻接数组*/
/*===============================================*/
/*输出邻接矩阵数据===============================*/
voidprint_M_Graph()
{
inti,j;
printf("
Vertice"
);
for(i=0;
i<
Max;
i++)
%3d"
i);
\n"
for(i=0;
{
%4d"
for(j=0;
j<
j++)
);
}
}
/*以邻接矩阵建立图形=============================*/
voidCreate_M_Graph(intVerticel,intVertice2)
Graph[Verticel][Vertice2]=1;
/*将矩阵内容设为1*/
/*主程序=========================================*/
voidmain()
intSource;
/*起始顶点*/
intDestination;
/*终止顶点*/
Graph[i][i]=0;
while
(1)
pleaseinputtheEdge'
ssource:
"
scanf("
%d"
&
Source);
if(Source==-1)
break;
PleaseinputtheEdge'
sDestination:
Destination);
if(Source==Destination)/*出错:
自身循环*/
***Error***:
SelfLoop!
!
\n"
elseif(Source>
=Max||Destination>
=Max)/*出错:
超出范围*/
printf("
outofrange!
else/*调用建立邻接数组*/
Create_M_Graph(Source,Destination);
##Graph##\n"
;
/*调用输出邻接数组数据*/
/*希望的结果*/
/*pleaseinputtheEdge'
0*/
/*PleaseinputtheEdge'
4*/
1*/
2*/
3*/
-1*/
/*##Graph##*/
/*Vertice012345*/
/*0000010*/
/*1100010*/
/*2010000*/
/*3001000*/
/*4000100*/
/*5000000*/
(二)将一个将图转成邻接表的程序.
/*用户输入结点与各个边,再将边转成邻接链表。
#include<
stdlib.h>
#definevertexnum6/*定义最大可输入的结点个数*/
typedefstructnode/*定义图形的顶点结构*/
intvertex;
structnode*next;
}Graph;
Graphhead[vertexnum];
/*以邻接链表建立图形=============================*/
voidCreate_l_Graph(intVertex1,intVertex2)
Graph*searchP;
/*结点声明*/
Graph*New;
/*新结点声明*/
New=(Graph*)malloc(sizeof(structnode));
if(New!
=NULL)
New->
vertex=;
next=NULL;
searchP=&
(head[Vertex1]);
while(searchP->
next!
=NULL)
searchP->
next=New;
/*输出邻接链表的数据===============================*/
voidprint_l_graph(structnode*head)
searchP=head->
next;
while(searchP!
[%d]"
searchP->
vertex);
searchP=searchP->
vertexnum;
head[i].vertex=i;
head[i].next=NULL;
elseif(Source>
=vertexnum||Destination>
=vertexnum)
/*出错:
else/*调用建立邻接链表*/
Create_l_Graph(Source,Destination);
=vertexnum;
vertex[%d]:
print_l_graph(&
head[i]);
/*调用输出邻接链表数据*/
/*PleaseinputtheEdg
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验六 图基本操作的编程实现 实验 基本 操作 编程 实现