exercism/go/pov/pov_helper.go

25 lines
413 B
Go

package pov
import (
"fmt"
"strings"
)
func PrintGraph(g *Graph) {
for i := range g.leaves {
PrintNode(&g.leaves[i], 1)
}
}
func PrintNode(n *Node, lvl int) {
fmt.Print(strings.Repeat(" ", lvl))
if n.parent == nil {
fmt.Println("{label:", n.label, "}")
} else {
fmt.Println("{label:", n.label, ", parent:", n.parent.label, "}")
}
for i := range n.leaves {
PrintNode(&n.leaves[i], lvl+1)
}
}