Created
May 2, 2022 21:23
-
-
Save sausheong/3fbe21504d37b6d29dc82b8b23ea7d15 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
func buildGraph() *Graph { | |
graph := NewGraph() | |
nodes := make(map[string]*Node) | |
for _, name := range []string{"A", "B", "C", "D", "E", "F", "G"} { | |
n := &Node{name, 0} | |
graph.AddNode(n) | |
nodes[name] = n | |
} | |
graph.AddEdge(nodes["A"], nodes["B"], 7) | |
graph.AddEdge(nodes["A"], nodes["D"], 4) | |
graph.AddEdge(nodes["B"], nodes["C"], 11) | |
graph.AddEdge(nodes["B"], nodes["D"], 9) | |
graph.AddEdge(nodes["B"], nodes["E"], 10) | |
graph.AddEdge(nodes["C"], nodes["E"], 5) | |
graph.AddEdge(nodes["D"], nodes["E"], 15) | |
graph.AddEdge(nodes["D"], nodes["F"], 6) | |
graph.AddEdge(nodes["E"], nodes["F"], 12) | |
graph.AddEdge(nodes["E"], nodes["G"], 8) | |
graph.AddEdge(nodes["F"], nodes["G"], 13) | |
return graph | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment