
找拓扑的算法:


public void topo() // toplogical sort
{
int orig_nVerts = nVerts; // remember how many verts
while(nVerts > 0) // while vertices remain,
{
// get a vertex with no successors, or -1
int currentVertex = noSuccessors();
if(currentVertex == -1) // must be a cycle
{
System.out.println("ERROR: Graph has cycles");
return;
}
// insert vertex label in sorted array (start at end)
sortedArray[nVerts-1] = vertexList[currentVertex].label;
deleteVertex(currentVertex); // delete vertex
} // end while
// vertices all gone; display sortedArray
System.out.print("Topologically sorted order: ");
for(int j=0; j<orig_nVerts; j++)
System.out.print( sortedArray[j] );
System.out.println("");
} // end topo
Warshall算法



本文介绍了一种实现拓扑排序的算法,并详细解释了其工作原理及流程。此外,还提到了Warshall算法,该算法用于解决图论中的路径问题。通过本文,读者可以了解这两种算法的基本概念及其应用。

被折叠的 条评论
为什么被折叠?



