这个是陈越数据结构第六章的习题6.12
构造了邻接矩阵存储,初始化时全部为零
#include<iostream>
using namespace std;
typedef int Vertex;
const int MaxVertexNum = 4;
typedef struct GNode * MGraph;
const int Infinity = 10;
int Dist[MaxVertexNum][MaxVertexNum], Path[MaxVertexNum][MaxVertexNum];
struct GNode {
int Nv;
int Ne;
int G[MaxVertexNum][MaxVertexNum];
};
typedef struct ENode * Edge;
struct ENode {
Vertex V1, V2;
int Weight;
};
MGraph CreatGraph(int N)
{
MGraph Graph = new struct GNode;
Graph->Nv = N;
Graph->Ne = 0;
for (Vertex V = 0; V < Graph->Nv; V++)
for (Vertex W = 0; W < Graph->Nv; W++)
Graph->G[V][W] = 0;
return Graph;
}
void Insert(MGraph Graph, Edge E)
{
Graph->G[E->V1][E->V2] = E->Weight;
}
MGraph BuildGraph()
{
int Nv;
MGraph Graph;
cin >> Nv;
cin.get(