Ex_GoAlgorithms/graphWidth.go
2024-05-30 11:50:30 +04:00

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)
}
}
}
}