23 lines
385 B
Go
23 lines
385 B
Go
package main
|
|
|
|
type GraphNodeWidth struct {
|
|
Value string
|
|
Visited bool
|
|
Edges []*GraphNodeWidth
|
|
}
|
|
|
|
func BFS(start *GraphNodeWidth, f func(*GraphNodeWidth)) {
|
|
queue := []*GraphNodeWidth{start}
|
|
for len(queue) > 0 {
|
|
node := queue[0]
|
|
queue = queue[1:]
|
|
node.Visited = true
|
|
f(node)
|
|
for _, n := range node.Edges {
|
|
if !n.Visited {
|
|
queue = append(queue, n)
|
|
}
|
|
}
|
|
}
|
|
}
|