algorithm 简单,高水平的实施

示例

如果没有创建循环,请按值对边进行排序,然后将每个边按排序顺序添加到MST中。

algorithm kruskalMST(G: a graph)
    sort G's edges by their value
    MST = an empty graph
    for each edge e in G:
        if adding e to MST does not create a cycle:
            add e to MST

    return MST