Created
May 3, 2022 08:50
-
-
Save sausheong/f1a4220b33b7dd02eab3416a379f4584 to your computer and use it in GitHub Desktop.
mst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| unc main() { | |
| graph := buildGraph() | |
| fmt.Println("GRAPH\n-----") | |
| nodes := sortNodes(graph.Nodes) | |
| for _, node := range nodes { | |
| fmt.Printf("%s -> %v\n", node.name, graph.Edges[node.name]) | |
| } | |
| fmt.Println() | |
| bMST := boruvka(graph) | |
| fmt.Println("BORUVSKA MINIMUM SPANNING TREE\n-----------------------------") | |
| nodes = sortNodes(bMST.Nodes) | |
| for _, node := range nodes { | |
| fmt.Printf("%s -> %v\n", node.name, bMST.Edges[node.name]) | |
| } | |
| fmt.Println() | |
| kMST := kruskal(graph) | |
| fmt.Println("KRUSKAL MINIMUM SPANNING TREE\n-----------------------------") | |
| nodes = sortNodes(kMST.Nodes) | |
| for _, node := range nodes { | |
| fmt.Printf("%s -> %v\n", node.name, kMST.Edges[node.name]) | |
| } | |
| fmt.Println() | |
| pMST := prim(graph, "A") | |
| fmt.Println("PRIM MINIMUM SPANNING TREE\n-------------------------") | |
| nodes = sortNodes(pMST.Nodes) | |
| for _, node := range nodes { | |
| fmt.Printf("%s -> %v\n", node.name, pMST.Edges[node.name]) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment