📄 m_graph.java
字号:
/* =============== Program Description =============== */
/* 程序名称: m_Graph.c */
/* 程序目的: 设计一个将图形转成邻接数组的程序。 */
/* Written By Kuo-Yu Huang. (WANT Studio.) */
/* =================================================== */
#define Max 6 /* 定义最大可输入数 */
int Graph[Max][Max]; /* 图形邻接数组 */
/* --------------------------------------------------- */
/* 输出邻接数组数据 */
/* --------------------------------------------------- */
void Print_M_Graph()
{
int i,j;
printf("Vertice");
for ( i=0;i<Max;i++)
printf("%3d",i);
printf("\n");
for ( i=0;i<Max;i++)
{
printf("%4d ",i);
for ( j=0;j<Max;j++ )
printf("%3d",Graph[i][j]);
printf("\n");
}
}
/* --------------------------------------------------- */
/* 以邻接数组建立图形 */
/* --------------------------------------------------- */
void Create_M_Graph(int Vertice1,int Vertice2)
{
Graph[Vertice1][Vertice2] = 1; /* 将数组内容设为1 */
}
/* --------------------------------------------------- */
/* 主程序 */
/* --------------------------------------------------- */
void main ()
{
int Source; /* 起始顶点 */
int Destination; /* 终止顶点 */
int i,j;
for ( i=0;i<Max;i++ )
for ( j=0;j<Max;j++)
Graph[i][j] = 0;
while ( 1 )
{
printf("Please input the Edge's source : ");
scanf("%d",&Source);
if ( Source == -1 )
break;
printf("Please input the Edge's Destination : ");
scanf("%d",&Destination);
if ( Source == Destination ) /* 错误:自身循环 */
printf("@Error@ : Self Loop!!\n");
/* 错误:超出范围 */
else if ( Source >= Max || Destination >= Max)
printf("@Error@ : Out of range!!\n");
else /* 调用建立邻接数组 */
Create_M_Graph(Source,Destination);
}
printf("##Graph##\n");
Print_M_Graph(); /* 调用输出邻接数组数据 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -