-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (35 loc) · 838 Bytes
/
main.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
package main
import (
"fmt"
"log"
)
func main() {
// Some test data
indexes := []int64{1, 2, 3, 4, 5, 6, 7, 8}
data := []string{"alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel"}
// Create our tree
tree := &Tree{}
for i, index := range indexes {
err := tree.Insert(index, data[i])
if err != nil {
log.Fatal(err)
}
}
fmt.Print("Sorted values: | ")
tree.Traverse(tree.Root, func(n *Node) { fmt.Print(n.Index, ": ", n.Data, " | ") })
fmt.Println()
search := int64(4)
fmt.Print("Find node '", search, "': ")
d, err := tree.Find(search)
if err != nil {
log.Fatal(err)
}
fmt.Println(d)
err = tree.Delete(search)
if err != nil {
log.Fatal(err)
}
fmt.Print("Sorted values: | ")
tree.Traverse(tree.Root, func(n *Node) { fmt.Print(n.Index, ": ", n.Data, " | ") })
fmt.Println()
}