Documentation
¶
Overview ¶
Package tree provides implementation to get and print formatted tree.
Example:
import "github.com/shivamMg/ppds/tree"
// a tree node.
type Node struct {
data int
children []*Node
}
func (n *Node) Data() interface{} {
return strconv.Itoa(n.data)
}
// cannot return n.children directly.
// https://github.com/golang/go/wiki/InterfaceSlice
func (n *Node) Children() (c []tree.Node) {
for _, child := range n.children {
c = append(c, tree.Node(child))
}
return
}
// n1, n2 := Node{data: "b"}, Node{data: "c"}
// n3 := Node{"a", []*Node{&n1, &n2}}
// tree.Print(&n3)
Index ¶
Constants ¶
View Source
const ( BoxVer = "│" BoxHor = "─" BoxVerRight = "├" BoxDownLeft = "┐" BoxDownRight = "┌" BoxDownHor = "┬" BoxUpRight = "└" // Gutter is number of spaces between two adjacent child nodes Gutter = 2 )
Variables ¶
This section is empty.
Functions ¶
func PrintHr ¶
func PrintHr(root Node)
PrintHr prints the horizontal formatted tree to standard output.
Types ¶
Click to show internal directories.
Click to hide internal directories.