邻接多重表的构造函数逻辑是 怎样的?
public AMLGraph(char[] vertexs, Edge[] edges) {
vexNum = vertexs.length;
edgeNum = edges.length;
vexs = new vexNode[vexNum];
for (int i = 0; i < vexNum; i++) {
vexs[i] = new vexNode();
vexs[i].data = vertexs[i];
vexs[i].firstEdge = null;
}
for (int i = 0; i < edgeNum; i++) {
char iData = edges[i].iData;
char jData = edges[i].jData;
int iVex = indexOfVex(iData);
int jVex = indexOfVex(jData);
edgeNode edge = new edgeNode(iVex, jVex);
if (vexs[iVex].firstEdge == null) {
vexs[iVex].firstEdge = edge;
} else {
edgeNode nextEdge = vexs[iVex].firstEdge;
nextEdge.iLink = nextEdge;
vexs[iVex].firstEdge = edge;
}
if (vexs[jVex].firstEdge == null) {
vexs[jVex].firstEdge = edge;
} else {
edgeNode nextEdge = vexs[jVex].firstEdge;
nextEdge.jLink = nextEdge;
vexs[jVex].firstEdge = edge;
}
}
}