Skip to content

Commit 316c242

Browse files
committed
Add utility IsLeaf() method
1 parent cf3731a commit 316c242

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

node.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ type node struct {
1010
childCount int
1111
}
1212

13-
func (n *node) setChildNode(newNode *node) bool {
14-
//fmt.Printf("settingChildNode: %v\n", newNode)
15-
n.childCount++
16-
n.children = []*node{newNode}
17-
return true
13+
func (n *node) IsLeaf() bool {
14+
return n.childCount == 0
1815
}
1916

2017
func (n *node) makeChildNode(s string) *node {
@@ -29,6 +26,13 @@ func (n *node) makeChildNode(s string) *node {
2926
return &child
3027
}
3128

29+
func (n *node) setChildNode(newNode *node) bool {
30+
//fmt.Printf("settingChildNode: %v\n", newNode)
31+
n.childCount = 1
32+
n.children = []*node{newNode}
33+
return true
34+
}
35+
3236
func makeNode(s string) node {
3337
//fmt.Printf("makingNode: %s\n", s)
3438
return node{value: s, childCount: 0}

0 commit comments

Comments
 (0)