思路:与无向图的邻接矩阵转邻接表相似
1 void ALGraphToReverseGraph(ALGraph AL,ALGraph &RAL) 2 { 3 RAL.vexnum = AL.vexnum; 4 RAL.arcnum = AL.arcnum; 5 for (int i = 0; i < AL.vexnum; ++i) { 6 RAL.vertices[i].data = AL.vertices[i].data; 7 RAL.vertices[i].firstarc = nullptr; 8 } 9 10 for (int i = 0; i < AL.vexnum; ++i) { 11 ArcNode *p = AL.vertices[i].firstarc; 12 while (p) { 13 ArcNode *arc = new ArcNode; 14 arc->adjvex = i; 15 arc->nextarc = RAL.vertices[p->adjvex].firstarc; 16 RAL.vertices[p->adjvex].firstarc = arc; 17 p = p->nextarc; 18 } 19 } 20 }