Kruskal's Algorithm:

 

 

public void FloydWarshall(Graph g)

{

    Set minSpanningTree = new Set();

    SetCollection allSets = new SetCollection();

    foreach( Vertex v in g)

    {

        Set temp = new Set(v);

        allSets.add(temp);

    }

 

    PriorityQueue unprocessedEdges = new PriorityQueue();

    // PriorityQueue is a min-heap

    foreach(Edge e in g)

    {

        unprocessedEdges.add(e);

    }

    unprocessedEdges.BuildHeap();

 

    // When we have a number of edges that is one less

    // than the number of vertices, then we span all the vertices

    // and we're done

    while( minSpanningTree.size < g.NumberOfVertices - 1 )

    // we could also do: while( ! unprocessedEdges.isEmpty() )

    {

        Edge currentEdge = unprocessedEdges.getMin(); // this will remove

        // the lowest-weight edge,and also re-heapify

        Vertex from = allSets.findSetContaining( currentEdge.start );

        Vertex to = allSets.findSetContaining( currentEdge.end );

        if( from != to) // in C#, you may need something like

        // if( ! from.equals(to) )

        {

            minSpanningTree.add(currentEdge);

            allSets.remove(to);

            from.addAll(to); // basically: merge these two sets

        }

    }

}