LGraph初始化
- 初始化一个有VertexNum个顶点但没有边的图
typedef int Vertex;
LGraph CreateGraph(int VertexNum)
{
Vertex V,W;
LGraph Graph;
Graph = (LGraph)malloc(sizeof(struct GNode));
Graph->Nv=VertexNum;
Graph->Ne=0;
for (V=0;V<Graph->Nv;V++)
Graph->G[V].FirstEdge=NULL;
return Graph;
}
向LGraph中插入边
void InsertEdge(LGraph Graph,Edge E)
{
PtrToAdjVNode NewNode;
NewNode=(PtrToAdjVNode)malloc(sizeof(struct AdjVNode));
NewNode->AdjV=E->v2;
NewNode->Weight=E->Weight;
NewNode->Next=Graph->G[v1].FirstEdge;
Graph->G[E->v1].FistEdge=NewNode;
}
完整地建立LGraph