2019-07-30 15:26:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.klmp200.net/klmp200/kvs/btree"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-07-30 23:19:09 +00:00
|
|
|
|
|
|
|
// Example program
|
2019-07-30 15:26:36 +00:00
|
|
|
t := btree.NewBtree(3)
|
2019-07-30 23:19:09 +00:00
|
|
|
t.Insert("animal", "dog")
|
2019-07-31 12:09:13 +00:00
|
|
|
|
|
|
|
s, _ := t.Search("animal")
|
|
|
|
fmt.Println(s)
|
|
|
|
|
2019-07-30 23:19:09 +00:00
|
|
|
t.Insert("potato", "fries")
|
|
|
|
t.Insert("6", "number")
|
|
|
|
t.Insert("12", "number")
|
|
|
|
t.Insert("car", "ferrari")
|
|
|
|
t.Insert("7", "number")
|
|
|
|
t.Insert("plane", "airbus")
|
2019-07-31 12:09:13 +00:00
|
|
|
t.Insert("animal", "cat")
|
|
|
|
|
|
|
|
s, _ = t.Search("animal")
|
|
|
|
fmt.Println(s)
|
2019-07-30 15:26:36 +00:00
|
|
|
|
|
|
|
fmt.Print("Traversal of the constructed tree is")
|
|
|
|
t.Traverse()
|
|
|
|
|
2019-07-31 12:09:13 +00:00
|
|
|
fmt.Println("")
|
|
|
|
|
|
|
|
t.Visualize()
|
|
|
|
|
2019-07-30 23:19:09 +00:00
|
|
|
if val, err := t.Search("6"); err != nil {
|
2019-07-30 15:26:36 +00:00
|
|
|
fmt.Print("\nNot Present")
|
2019-07-30 23:19:09 +00:00
|
|
|
} else {
|
|
|
|
fmt.Printf("\nPresent: value '%s'", val)
|
2019-07-30 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 23:19:09 +00:00
|
|
|
if val, err := t.Search("15"); err != nil {
|
2019-07-30 15:26:36 +00:00
|
|
|
fmt.Print("\nNot Present")
|
2019-07-30 23:19:09 +00:00
|
|
|
} else {
|
|
|
|
fmt.Printf("\nPresent: value '%s'", val)
|
2019-07-30 15:26:36 +00:00
|
|
|
}
|
2019-07-31 12:09:13 +00:00
|
|
|
|
2019-07-30 15:26:36 +00:00
|
|
|
}
|