Ex_GoAlgorithms/graphList.go

27 lines
411 B
Go
Raw Normal View History

2024-05-30 11:50:30 +04:00
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)
}
}