Kotlin library providing simple interface to work with data for some types of binary trees
- Binary Search Tree
- AVL Tree
- Red-Black Tree
- Two-Three Tree
import monke.trees.BSTree
fun main() {
val bst = BSTree<Int, String>()
bst.insert(1, "Example value for search method")
println(bst.search(1)) // Example value for search method
}- Arithmetic operations - add and subtract interface for two trees to insert or remove all nodes of one tree into/from another one
- Get operator - retrieving values using the get operator with a key
import monke.trees.BSTree
fun main() {
val bst = BSTree<Int, String>()
bst.insert(1, "Example value for get method")
println(bst[1]) // Example value for get method
}import monke.trees.BSTree
fun main() {
val tree1 = BSTree<Int, String>()
val tree2 = BSTree<Int, String>()
tree1.insert(1, "value from first tree")
tree2.insert(2, "value from second tree")
val tree3 = tree1.copy() + tree2
tree3.insert(-1, "value from third tree")
for (i in tree3) {
println(i)
}
/*
(1, value from first tree)
(-1, value from third tree)
(2, value from second tree)
*/
}Important
Inserting a node with an existing key results in an error. Ensure keys are unique before inserting.
import monke.trees.BSTree
fun main() {
var tree1 = BSTree<Int, String>()
tree1.insert(1, "value 1")
tree1.insert(2, "value 2")
tree1.insert(3, "value 3")
val tree2 = tree1.copy()
tree1.insert(4, "value 4")
tree1 -= tree2
for (i in tree1) {
println(i)
}
/*
(4, value 4)
*/Important
As in addition, try to delete a key that does not exist in the tree throws an error.
To generate documentation, run:
./gradlew dokkaHtml
from the project root.
This project is licensed under the MIT License.
