-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_tree_test.go
112 lines (99 loc) · 1.47 KB
/
binary_tree_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package algorithm
import (
"fmt"
"testing"
)
func TestBinaryTree_Search(t *testing.T) {
tree := NewBinaryTree()
tree.Insert(5)
tree.Insert(7)
tree.Insert(4)
fmt.Println(tree.Search(4))
}
func TestBinaryTree_MiddleShow(t *testing.T) {
tree := NewBinaryTree()
tree.Insert(5)
tree.Insert(2)
tree.Insert(7)
tree.Insert(1)
tree.Insert(3)
tree.Insert(6)
tree.Insert(8)
tree.MiddleShow()
}
func TestNewBinaryTree(t *testing.T) {
tree := NewBinaryTree()
tree.Insert(5)
tree.Insert(2)
tree.Insert(7)
tree.Insert(1)
tree.Insert(3)
tree.Insert(6)
tree.Insert(8)
tree.FirstShow()
}
func TestBinaryTree_LevelShow(t *testing.T) {
tree := NewBinaryTree()
tree.Insert(2)
tree.Insert(1)
tree.Insert(3)
tree.LevelShow()
}
func TestBinaryTree_FirstShow(t *testing.T) {
tree := NewBinaryTree()
tree.Insert(5)
tree.Insert(2)
tree.Insert(7)
tree.Insert(1)
tree.Insert(3)
tree.Insert(6)
tree.Insert(8)
tree.Reverse()
tree.MiddleShow()
}
func TestInvertTree(t *testing.T) {
root := &TreeNode{
Val: 4,
Left: &TreeNode{
2,
&TreeNode{
1,
nil,
nil,
},
&TreeNode{
3,
nil,
nil,
},
},
Right: &TreeNode{
7,
&TreeNode{
6,
nil,
nil,
},
&TreeNode{
9,
nil,
nil,
},
}}
tree := invertTree(root)
t.Log(tree)
}
func TestFindMode(t *testing.T) {
root := &TreeNode{
Val: 1,
Left: nil,
Right: &TreeNode{
Val: 2,
Left: &TreeNode{
Val: 2,
},
},
}
tree := findMode(root)
t.Log(tree)
}