Skip to content

spbu-coding-2023/trees-2

Repository files navigation

forest-group

Kotlin 1.9.23 Tests passing Code Coverage License

forest-group is a library that lets you easily create and use Binary search trees, AVL trees and Red-black trees in your applications!

Table of contents

About The Project

Trees are well-known for their speed and efficiency.

But there are lots of tree implementations that are strict to data types that can be stored.

The solution is easy - just use keys to store anything you want!

Usage

To create a tree, pass the key type and your stored data type to a generic. Note that your key should implement Comparable type.

val myBSTree = BSTree<Int, String>()

val myAVLTree = AVLTree<Char, Long>()

val myRBTree = RBTree<String, Float>()

You now can simply insert and replace values in your tree:

val myKey = 10

myBSTree.insert(myKey, "Something important")

val replacedValue = myBSTree.insert(myKey, "Something more important")

You can also search for values and delete values from tree by keys:

val myValue1 = myBSTree.search(myKey)

val myValue2 = myBSTree.delete(myKey)

println(myValue1 == myValue2) // true

All trees are iterable by Pair(key, value), so they can be used in a for loop.

Iterator implements inorder traversal (every next key is greater than the previous).

for ((key, value) in myRBTree) {
    keysList.add(key)
    valuesList.add(value)
}

myRBTree.forEach { println(it) } // prints every pair

Contributing

If you have found a bug, or want to propose some useful feature for our project, please firstly read our Contribution Rules and do the following:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/my-feature)
  3. Commit your Changes (git commit -m 'add some feature')
  4. Push to the Branch (git push origin feature/my-feature)
  5. Open a Pull Request

License

Distributed under the MIT License.

Authors


Java gnomik

About

trees-2 created by GitHub Classroom

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages