btree: add a way to visualize the tree
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user