-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.go
More file actions
44 lines (35 loc) · 740 Bytes
/
Copy pathgraph.go
File metadata and controls
44 lines (35 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"strings"
)
type TestNode struct {
Key string
Test *Test
Config *TestGroup
Children []*TestNode
}
func addChildNode(root, child *TestNode, parentKey string) bool {
if parentKey == root.Key {
root.Children = append(root.Children, child)
return true
}
for _, node := range root.Children {
if addChildNode(node, child, parentKey) {
return true
}
}
return false
}
func printNode(node *TestNode, depth int) {
fmt.Printf("%s- %v\n", strings.Repeat(" ", depth), node.Key)
}
func printGraph(root *TestNode) {
_printGraph(root, 0)
}
func _printGraph(root *TestNode, depth int) {
printNode(root, depth)
for _, child := range root.Children {
_printGraph(child, depth+1)
}
}