#include <iostream>
using namespace std;
#define MAXVEX 100
#define INFINITY 65535
typedef char VertexType;
typedef int EdgeType;
typedef struct
{
VertexType vexs[MAXVEX];
EdgeType arc[MAXVEX][MAXVEX];
int numVertexes, numEdges;
} MGraph;
void CreateMGraph(MGraph *G)
{
int i,j,k,w;
cout<<"输入顶点数和边数:";
cin>>G->numVertexes>>G->numEdges;
for(i=0; i<G->numVertexes; i++)
cin>>G->vexs[i];
for(i=0; i<G->numVertexes; i++)
for(j=0; j<G->numVertexes; j++)
G->arc[i][j] = INFINITY;
for(k=0; k<G->numEdges; k++)
{
cout<<"输入边(vi,vj)上的下标i 和下标j 以及边上的权值w:";
cin>>i>>j>>w;
G->arc[i][j] = w;
G->arc[j][i] = G->arc[i][j];
}
}
#include <iostream>
using namespace std;
#define MAXVEX 100
typedef char VertexType;
typedef int EdgeType;
typedef struct EdgeNode
{
int adjvex;
EdgeType weight;
struct EdgeNode *next;
} EdgeNode;
typedef struct VertexNode
{
VertexType data;
EdgeNode *firstedge;
} VertexNode, AdjList[MAXVEX];
typedef struct
{
AdjList adjList;
int numVertexes,numEdges;
} GraphAdjList;
void CreateALGraph(GraphAdjList *G)
{
int i,j,k;
EdgeType w;
EdgeNode *e;
cout<<"输入顶点数和边数:";
cin>>G->numVertexes>>G->numEdges;
cout<<"输入各顶点的信息:"<<endl;
for(i=0; i<G->numVertexes; i++)
{
cin>>G->adjList[i].data;
G->adjList[i].firstedge = NULL;
}
cout<<"输入各边(vi,vj)上的顶点序号以及权值:"<<endl;
for(k=0; k<G->numEdges; k++)
{
cin>>i>>j>>w;
e = new EdgeNode;
e->adjvex = j;
e->weight = w;
e->next = G->adjList[i].firstedge;
G->adjList[i].firstedge = e;
e->adjvex = i;
e->weight = w;
e->next = G->adjList[j].firstedge;
G->adjList[j].firstedge = e;
}
}