无向网图的建立

1.确定顶点数和边数
2.输入顶点表的信息
3.初始化邻接表
4.确定权

#include
#define MAXVEX 100
#define INFINITY 65535
typedef char VertexType //顶点的数据类型 
typedef int EdgeType // 权值得类型 

typedef struct{
	VertexType vexs[MAXTEX];//顶点表 
	EdgeType arc[MAXTEX][MAXTEX];//邻接矩阵
	int NumOfVertex , NumOfEdge; // 图中的边的数量和顶点的数量 
}MyGraph;

void CreatGraph(MyGraph * g){
	int i = 0 , j = 0 , k = 0 , l = 0;
	printf("请输入顶点的数量和边的数量 : ");
	scanf("%d %d" ,&(g->NumOfVertex) , &(g->NumOfEdge));
	for(i = 0 , i < (g->NumOfVertex) , i++){
		scanf("%c" , &(g->vexs[i]));
	}
	for(i = 0 ; i < (g->NumOfVertex) ; i++){
		for(j = 0 ; j < (g->NumOfVertex) ; j++){
			g->arc[i][j] = INFINITY;
		}
	}
	for(k = 0 ; k < (g->NumOfEdge) ; k++){
		printf("输入边(vi , vj)上的下标 i , j 和 权");
		scanf("%d %d %d " , &i , &j , &k);
		g->arc[i][j] = k;
		g->arc[i][j] = g->arc[j][i];//因为是无向边 , 矩阵对称 
	}
	 
}

你可能感兴趣的:(数据结构学习笔记)