Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a89c7d5

Browse files
add Show
1 parent dc8a177 commit a89c7d5

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

‎BST/bst.go

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@ func main() {
99
tree.Insert(1)
1010
tree.Insert(2)
1111
fmt.Println("Size: ", tree.Size())
12+
fmt.Println("Show: ")
13+
tree.Show()
1214
fmt.Println("Insert 3 1 3")
1315
tree.Insert(3)
1416
tree.Insert(1)
1517
tree.Insert(3)
1618
fmt.Println("Size: ", tree.Size())
19+
fmt.Println("Show: ")
20+
tree.Show()
1721
fmt.Println("Search 4: ", tree.Search(4))
1822
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()
1930
}
2031

2132
// Node is a representation of a single node in tree. (recursive ADT)
@@ -38,6 +49,7 @@ Binary Search Tree ADT Operations
3849
* + Search(k): поиск значения элемента k в структуре, есть он или нет.
3950
* FindMax(): поиск максимального значения.
4051
* FindMin(): поиск минимального значения.
52+
* Show & Size(): печать дерева и размер.
4153
*/
4254

4355
// New - Construtor BST
@@ -103,6 +115,11 @@ func searchElement(root *Node, value int) bool {
103115
return false
104116
}
105117

118+
// Show the tree (Print the tree in-order)
119+
func (tree *Bst) Show() {
120+
showInOrder(tree.root)
121+
}
122+
106123
// Print the tree in-order
107124
// Traverse the left sub-tree, root, right sub-tree
108125
func showInOrder(root *Node) {
@@ -112,23 +129,3 @@ func showInOrder(root *Node) {
112129
showInOrder(root.right)
113130
}
114131
}
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /