forked from TheAlgorithms/Go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarytree.go
More file actions
38 lines (36 loc) · 758 Bytes
/
binarytree.go
File metadata and controls
38 lines (36 loc) · 758 Bytes
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
// Package binarytree basic binary tree and related operations
package binarytree
/*
func main() {
t := BTree{nil}
t.Root = NewNode(0)
t.Root.left = NewNode(1)
t.Root.right = NewNode(2)
t.Root.left.left = NewNode(3)
t.Root.left.right = NewNode(4)
t.Root.right.left = NewNode(5)
t.Root.right.right = NewNode(6)
t.Root.right.right.right = NewNode(10)
InOrder(t.Root)
fmt.Print("\n")
PreOrder(t.Root)
fmt.Print("\n")
PostOrder(t.Root)
fmt.Print("\n")
LevelOrder(t.Root)
fmt.Print("\n")
fmt.Print(t.Depth(), "\n")
var list = AccessNodesByLayer(t.Root)
fmt.Println("{")
for i, v := range list {
for _, v2 := range v {
fmt.Print(" [", v2, "]")
}
if i != len(list)-1 {
fmt.Print(",")
}
fmt.Println()
}
fmt.Println("}")
}
*/