btree: add a way to visualize the tree

This commit is contained in:
2019-07-31 14:09:13 +02:00
parent bb83664e87
commit d99fc856c3
3 changed files with 73 additions and 10 deletions
+13
View File
@@ -11,16 +11,28 @@ func main() {
// Example program
t := btree.NewBtree(3)
t.Insert("animal", "dog")
s, _ := t.Search("animal")
fmt.Println(s)
t.Insert("potato", "fries")
t.Insert("6", "number")
t.Insert("12", "number")
t.Insert("car", "ferrari")
t.Insert("7", "number")
t.Insert("plane", "airbus")
t.Insert("animal", "cat")
s, _ = t.Search("animal")
fmt.Println(s)
fmt.Print("Traversal of the constructed tree is")
t.Traverse()
fmt.Println("")
t.Visualize()
if val, err := t.Search("6"); err != nil {
fmt.Print("\nNot Present")
} else {
@@ -32,4 +44,5 @@ func main() {
} else {
fmt.Printf("\nPresent: value '%s'", val)
}
}