https://github.com/lovesaroha/lbst
This is a generalized binary search tree package with clean and transparent API for the Go language.
https://github.com/lovesaroha/lbst
binary-search-tree golang golang-package
Last synced: 11 months ago
JSON representation
This is a generalized binary search tree package with clean and transparent API for the Go language.
- Host: GitHub
- URL: https://github.com/lovesaroha/lbst
- Owner: lovesaroha
- License: gpl-3.0
- Created: 2021-09-16T17:48:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-26T12:22:31.000Z (over 4 years ago)
- Last Synced: 2025-01-12T19:23:22.498Z (12 months ago)
- Topics: binary-search-tree, golang, golang-package
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lbst
This is a generalized binary search tree package with clean and transparent API for the Go language.
## Features
- Lightweight and Fast.
- Native Go implementation.
- Support all data types.
## Requirements
- Go 1.9 or higher. We aim to support the 3 latest versions of Go.
## Installation
Simple install the package to your [$GOPATH](https://github.com/golang/go/wiki/GOPATH "GOPATH") with the [go tool](https://golang.org/cmd/go/ "go command") from shell:
```bash
go get -u github.com/lovesaroha/lbst
```
Make sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`.
## Usage
### Create Binary Search Tree
```Golang
// Create a binary search tree.
bst := lbst.Create()
// Insert values.
bst.Insert(6)
bst.Insert(2)
bst.Insert(4)
// Search value (If not found return nil).
bst.Search(4)
// See values in order.
bst.InOrder()
```

### Binary Search Tree With Strings
```Golang
// Create a binary search tree.
bst := lbst.Create()
// Insert values.
bst.Insert("love")
bst.Insert("saroha")
bst.Insert("github")
// Search value (If not found return nil).
bst.Search("love")
// See values in order.
bst.InOrder()
```

### Add Multiple Values
```Golang
// Create a binary search tree.
bst := lbst.Create()
// Add values in bst.
bst.InsertValues([]interface{}{5,3,1,6,8,7,0,9})
// See values in order.
bst.InOrder()
```

### Binary Search Tree With Custom Data Type
```Golang
type user struct {
name string
age int
}
// Compare function for custom data type.
func compare(a interface{} , b interface{}) bool {
// For less than return true.
return a.(user).age <= b.(user).age
}
// Create a binary search tree.
bst := lbst.Create()
// Add values in bst.
bst.InsertWith(user{name: "love" , age: 27} , compare)
bst.InsertWith(user{name: "joe" , age: 30} , compare)
bst.InsertWith(user{name: "doe" , age: 34} , compare)
// See values in order.
bst.InOrder()
```
