1 #include "stdafx.h"
2 #include <iostream>
3 #include <exception>
4 #include<string>
5 using namespace std;
6 //邻接矩阵存储结构
7 typedef char VertexType;
8 typedef int EdgeType;//权值类型
9 const int maxVex = 100;//最大顶点数
10 const int inFinity = 65535;//代表无穷大
11 typedef struct
12 {
13 VertexType vexs[maxVex];//顶点表
14 EdgeType arc[maxVex][maxVex];//邻接矩阵
15 int numVertexes,numEdges;//图中当前顶点数和边数
16 }MGraph;
17 //建立无向网图的邻接矩阵
18 void CreateMGraph(MGraph *G)
19 {
20 int i,j,k,w;
21 cout<<"输入顶点数和边数"<<endl;
22 cin>>G->numVertexes>>G->numEdges;
23 for(i = 0;i<G->numVertexes;++i)//输入顶点信息.建立顶点表
24 cin>>G->vexs[i];
25 for(i = 0;i<G->numVertexes;i++)//邻接矩阵的初始化
26 for(j = 0;j<G->numVertexes;j++)
27 G->arc[i][j]=inFinity;
28 for(k=0;k<G->numEdges;++k)//读入numEdges条边,建立邻接矩阵
29 {
30 cout<<"输入边vi,vj上的下标i,j和权值w"<<endl;
31 cin>>i>>j>>w;
32 G->arc[i][j]=w;
33 G->arc[j][i]=G->arc[i][j];//无向图,对称
34 }
35 }
36
37 int _tmain(int argc, _TCHAR* argv[])
38 {
39
40
41 return 0 ;
42 }