Last active
March 20, 2022 03:06
-
-
Save sausheong/88f0f831c87f9eb1bb813b2d82b7b320 to your computer and use it in GitHub Desktop.
da
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 main() { | |
// build and run Dijkstra's algorithm on graph | |
graph := buildGraph() | |
city := os.Args[1] | |
dijkstra(graph, city) | |
// display the nodes | |
for _, node := range graph.Nodes { | |
fmt.Printf("Shortest time from %s to %s is %d\n", | |
city, node.name, node.value) | |
for n := node; n.through != nil; n = n.through { | |
fmt.Print(n, " <- ") | |
} | |
fmt.Println(city) | |
fmt.Println() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment