@@ -9,13 +9,24 @@ func main() {
9
9
tree .Insert (1 )
10
10
tree .Insert (2 )
11
11
fmt .Println ("Size: " , tree .Size ())
12
+ fmt .Println ("Show: " )
13
+ tree .Show ()
12
14
fmt .Println ("Insert 3 1 3" )
13
15
tree .Insert (3 )
14
16
tree .Insert (1 )
15
17
tree .Insert (3 )
16
18
fmt .Println ("Size: " , tree .Size ())
19
+ fmt .Println ("Show: " )
20
+ tree .Show ()
17
21
fmt .Println ("Search 4: " , tree .Search (4 ))
18
22
fmt .Println ("Search 3: " , tree .Search (3 ))
23
+ fmt .Println ("Insert 14 17 31" )
24
+ tree .Insert (14 )
25
+ tree .Insert (17 )
26
+ tree .Insert (31 )
27
+ fmt .Println ("Size: " , tree .Size ())
28
+ fmt .Println ("Show: " )
29
+ tree .Show ()
19
30
}
20
31
21
32
// Node is a representation of a single node in tree. (recursive ADT)
@@ -38,6 +49,7 @@ Binary Search Tree ADT Operations
38
49
* + Search(k): поиск значения элемента k в структуре, есть он или нет.
39
50
* FindMax(): поиск максимального значения.
40
51
* FindMin(): поиск минимального значения.
52
+ * Show & Size(): печать дерева и размер.
41
53
*/
42
54
43
55
// New - Construtor BST
@@ -103,6 +115,11 @@ func searchElement(root *Node, value int) bool {
103
115
return false
104
116
}
105
117
118
+ // Show the tree (Print the tree in-order)
119
+ func (tree * Bst ) Show () {
120
+ showInOrder (tree .root )
121
+ }
122
+
106
123
// Print the tree in-order
107
124
// Traverse the left sub-tree, root, right sub-tree
108
125
func showInOrder (root * Node ) {
@@ -112,23 +129,3 @@ func showInOrder(root *Node) {
112
129
showInOrder (root .right )
113
130
}
114
131
}
115
-
116
- // Print the tree pre-order
117
- // Traverse the root, left sub-tree, right sub-tree
118
- func showPreOrder (root * Node ) {
119
- if root != nil {
120
- fmt .Println (root .key )
121
- showInOrder (root .left )
122
- showInOrder (root .right )
123
- }
124
- }
125
-
126
- // Print the tree post-order
127
- // Traverse left sub-tree, right sub-tree, root
128
- func showPostOrder (root * Node ) {
129
- if root != nil {
130
- fmt .Println (root .key )
131
- showInOrder (root .left )
132
- showInOrder (root .right )
133
- }
134
- }
0 commit comments