Skip to content

Instantly share code, notes, and snippets.

@sausheong
Last active March 20, 2022 03:06
Show Gist options
  • Save sausheong/88f0f831c87f9eb1bb813b2d82b7b320 to your computer and use it in GitHub Desktop.
Save sausheong/88f0f831c87f9eb1bb813b2d82b7b320 to your computer and use it in GitHub Desktop.
da
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