邻接矩阵表示图及遍历修改程序#include#define INT_MAX 1000#define MaxVertice
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/08/17 18:02:08
邻接矩阵表示图及遍历
修改程序
#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 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 MaxVertice](/uploads/image/z/7409547-27-7.jpg?t=%E9%82%BB%E6%8E%A5%E7%9F%A9%E9%98%B5%E8%A1%A8%E7%A4%BA%E5%9B%BE%E5%8F%8A%E9%81%8D%E5%8E%86%E4%BF%AE%E6%94%B9%E7%A8%8B%E5%BA%8F%23include%23define+INT_MAX+1000%23define+MaxVertice)
#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
#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
邻接矩阵表示图及遍历修改程序#include#define INT_MAX 1000#define MaxVertice
括号匹配检验程序#include#include#define TRUE 1#define FALSE 0#define
#include #include #include #include #include /* define
#include #include #define TRUE 1 #define FALSE 0 #define OK
英语翻译#include #include #include #include #define WIN_CONSOLE
#include #include #define MAXLINE 1000int getline(char *line
#include#include#include#includeusing namespace std;#define
ds18b20测温#include#include#define uchar unsigned char#define
英语翻译#include#include#define uchar unsigned char#define uint
一道数据结构题:#include #include #define STACK_INIT_SIZE 100#define
C语言 中&和 请参照这个程序#include#define NULL 0struct student{int num;
#include#include#include#define LEN sizeof(struct LinkList)s