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

27 lines
411 B
Go

package main
import "fmt"
type GraphNode struct {
Name string
Children []*GraphNode
}
func NewNode(name string) *GraphNode {
return &GraphNode{
Name: name,
}
}
func (n *GraphNode) AddChild(name string) {
child := NewNode(name)
n.Children = append(n.Children, child)
}
func (n *GraphNode) Print() {
fmt.Println(n.Name)
for _, child := range n.Children {
fmt.Println(" -> ", child.Name)
}
}