-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode.go
58 lines (50 loc) · 985 Bytes
/
node.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import "time"
type Node struct {
FileName string
Year int
Month time.Month
Day int
Next *Node
Children *Node
}
func NewNode(fileName string, year int, month time.Month, day int) *Node {
return &Node{
FileName: fileName,
Year: year,
Month: month,
Day: day,
Next: nil,
Children: nil,
}
}
func (n *Node) HasNext() bool {
return n.Next != nil
}
func (n *Node) HasChildren() bool {
return n.Children != nil
}
func (n *Node) AddChild(node *Node) {
var oldNext = n.Children
n.Children = node
n.Children.Next = oldNext
}
// Search the children nodes for the value in the string
func (n *Node) Search(value string) *Node {
var cur = n.Children
for cur != nil {
if cur.FileName == value {
return cur
}
cur = cur.Next
}
return nil
}
func (n *Node) Visit(visitor NodeVisitor, depth int) {
visitor.Visit(n, depth)
var cur = n.Children
for cur != nil {
cur.Visit(visitor, depth+1)
cur = cur.Next
}
}