exercism/go/pov/pov_helper.go

25 lines
413 B
Go
Raw Normal View History

2017-08-15 22:06:46 +00:00
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) {
2017-08-17 18:12:16 +00:00
fmt.Print(strings.Repeat(" ", lvl))
if n.parent == nil {
fmt.Println("{label:", n.label, "}")
} else {
fmt.Println("{label:", n.label, ", parent:", n.parent.label, "}")
}
2017-08-15 22:06:46 +00:00
for i := range n.leaves {
PrintNode(&n.leaves[i], lvl+1)
}
}