## 如何在这个代码里面加入边的权值 求大神们指教

lzjuypf 发布于 2016/11/08 17:40

```#include <iostream>
using namespace std;
typedef struct edge
{
int Weight;
struct edge *NextEdge;
}EdgeType;
typedef struct
{
char Vertex;
EdgeType *FirstEdge;
}VertexType;
static int n;
static int e;
//static int w;
{
for (int k = 0; k < n; k++)
{
if (x==q[k].Vertex)
{
return k;
}
else
{
continue;
}
}
return 0;
}
{
int i,j;
char v1, v2;//边结点
EdgeType *p, *q;
cout << "输入图中顶点的个数n和边数e" << endl;
cin >> n;
cin >> e;
cout << "输入顶点的数据:";
for (int k = 0; k < n;k++)
{
cin >> Graph[k].Vertex;
Graph[k].FirstEdge = NULL;
}
cout << "输入图中各边" << endl;
for (int k = 0; k < e; k++)
{
cin >> v1 >> v2;
i = LocVertex(Graph, v1);
j = LocVertex(Graph, v2);
q = new EdgeType;
q->NextEdge = Graph[i].FirstEdge;
Graph[i].FirstEdge = q;

p = new EdgeType;
p->NextEdge = Graph[j].FirstEdge;
Graph[j].FirstEdge = p;

}
cout << "图的邻接表结构;"<<endl;
for (i = 0; i < n; i++)
{
cout << "i=" << i << endl;
v1 = Graph[i].Vertex;
cout << "Vertex:" << v1;
p = Graph[i].FirstEdge;
while (p!=NULL)
{
cout << "-->" << v2 <<" ";
p = p->NextEdge;
}
cout << endl;
}
return 0;
}
void main()
{