@@ -7,12 +7,12 @@ Implentation of a general tree in **Go Programming Language**. A general tree is
7
7
** Types:**
8
8
9
9
``` go
10
- type Node struct
10
+ type Node struct
11
11
Value interface {}
12
12
Children []*Node
13
13
}
14
14
15
- type GeneralTree struct
15
+ type GeneralTree struct
16
16
Root *Node
17
17
}
18
18
```
@@ -21,14 +21,10 @@ type GeneralTree struct
21
21
22
22
``` go
23
23
// Create a new general tree
24
- func NewGeneralTree () *GeneralTree
25
- return &GeneralTree{}
26
- }
24
+ func NewGeneralTree () *GeneralTree
27
25
28
26
// Create a new node
29
- func NewNode () *Node
30
- return &Node{}
31
- }
27
+ func NewNode() *Node
32
28
```
33
29
34
30
**Methods:**
@@ -41,24 +37,24 @@ func (t *GeneralTree) AddNode(value interface{})
41
37
func (t *GeneralTree ) AddNodeToParent (value int , parent *Node )
42
38
43
39
// Get the root node of the tree
44
- func (t *GeneralTree) GetRoot() *Node
40
+ func (t *GeneralTree) GetRoot() *Node
45
41
46
42
// Get the children of a node
47
- func (t *GeneralTree) GetChildren(node *Node) []*Node
43
+ func (t *GeneralTree) GetChildren(node *Node) []*Node
48
44
49
45
// Get the value of a node
50
- func (t *GeneralTree) GetValue(node *Node) interface{}
46
+ func (t *GeneralTree) GetValue(node *Node) interface{}
51
47
52
48
// Set the value of a node
53
49
func (t *GeneralTree ) SetValue (node *Node , value interface {})
54
50
55
51
// Get the number of nodes in the tree
56
- func (t *GeneralTree) GetSize() int
57
- func (t *GeneralTree) getSize(node *Node) int
52
+ func (t *GeneralTree) GetSize() int
53
+ func (t *GeneralTree) getSize(node *Node) int
58
54
59
55
// Get the height of the tree
60
- func (t *GeneralTree) getHeight() int
61
- func (t *Node) GetHeight(node *Node) int
56
+ func (t *GeneralTree) getHeight() int
57
+ func (t *Node) GetHeight(node *Node) int
62
58
63
59
// Print the tree
64
60
func (t *GeneralTree) PrintTree()
@@ -118,7 +114,7 @@ func main()
118
114
// Get the children of the root node
119
115
child := tree.GetChildren (tree.Root )
120
116
fmt.Println (" Children of the root node: " , tree.GetChildren (tree.Root ))
121
- for _ , c := range child
117
+ for _ , c := range child
122
118
fmt.Println (" \t Children of the root node: " , c.Value )
123
119
}
124
120
0 commit comments