邻接矩阵表示图及遍历修改程序#include#define INT_MAX 1000#define MaxVerticesNum 10int visited[MaxVerticesNum]={0};typedef char VertexType;typedef int EdgeType;typedef struct {VertexType vexs[MaxVerticesNum];/*顶点表*/EdgeType edges[Ma
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 02:13:52
邻接矩阵表示图及遍历修改程序#include#define INT_MAX 1000#define MaxVerticesNum 10int visited[MaxVerticesNum]={0};typedef char VertexType;typedef int EdgeType;typedef struct {VertexType vexs[MaxVerticesNum];/*顶点表*/EdgeType edges[Ma
邻接矩阵表示图及遍历
修改程序
#include
#define INT_MAX 1000
#define MaxVerticesNum 10
int visited[MaxVerticesNum]={0};
typedef char VertexType;
typedef int EdgeType;
typedef struct {
VertexType vexs[MaxVerticesNum];/*顶点表*/
EdgeType edges[MaxVerticesNum] [MaxVerticesNum];
int n,e;
}Mgraph;
void CreateMGraph(Mgraph *G){
/*建立无向网络的邻接矩阵表示*/
int i,j,k,w;
scanf("n=%d,e=%d",&G->n,&G->e);
for (i = 0; i < G->n; i++ )
G->vexs[i] = getchar();
for (i = 0; i < G->n; i++ )
for (j = 0; j < G->n; j++ ) G->edges[i][j] = INT_MAX;
for(k = 0; k < G->e; k++) {
scanf("%d,%d,%d",&i,&j,&w);
G-> edges[i][j] = w;
}
}
void DFSM (Mgraph *G,int i){
int j;
printf("visit vertex:%c",G->vexs[i]);
visited[i] = 1; /*标记vi已访问*/
for(j = 1; j n; j++)
if(G->edges[i][j] == 1 && visited[j])
DFSM(G,j);
}
main()
{
Mgraph G;
CreateMGraph(&G);
DFSM (&G,1);
}
邻接矩阵表示图及遍历修改程序#include#define INT_MAX 1000#define MaxVerticesNum 10int visited[MaxVerticesNum]={0};typedef char VertexType;typedef int EdgeType;typedef struct {VertexType vexs[MaxVerticesNum];/*顶点表*/EdgeType edges[Ma
#include
#define INT_MAX 1000
#define MaxVerticesNum 10
int visited[MaxVerticesNum]={0};
typedef char VertexType;
typedef int EdgeType;
typedef struct {
VertexType vexs[MaxVerticesNum];/*顶点表*/
EdgeType edges[MaxVerticesNum] [MaxVerticesNum];
int n,e;
}Mgraph;
//建立图
void CreateMGraph(Mgraph &G)
{
G.n = 8;
G.e = 9;
for(int i=0;i