Code Monkey home page Code Monkey logo

trees-3's Introduction

Binary search trees library

An open source library written in Kotlin to work with data structures such as AVL tree, red-black tree, and binary search tree.

๐Ÿ– Used technology

Kotlin Junit Neo4j Postgresql Docker

๐Ÿ“ฆ Getting started

To build the library run

./gradlew build

To run PostgreSQL with docker:

./start-db.sh

or

./start-db.bat

Using binary search trees

Any data (provided with Comparable key) can be stored in trees. For example:

    import bst.BSTree
    val tree = BSTree(1, "apple")
    tree.insert(7, "orange")
    tree.insert(28, "Alice")
    tree.insert(4, "Bob")

Constructor takes two arguments: key and value, thus instantiating a root node (you can delete it, but you cannot create an empty tree). insert method also takes same arguments and adds a node with specified key and value properties to the tree. Method setName allows you to set the name of a tree.

Find or remove element from tree:

    tree.find(4) // returns "Bob"
    tree.remove(1) 

find and remove methods take some Comparable key as an argument.

AVL and red-black trees implement the same methods.

Storing binary search trees

AVL tree can be saved to and loaded from JSON file. For example:

    val tree = AVLTree(1, "apple")
    tree.setName("test")
    val controller = JsonController()
    controller.saveTreeToJson(test)
    println(controller.readFromJson("test")?.treeName)

You can also save binary search tree to SQL database:

    val tree = BSTree(1, "apple")
    tree.setName("test")
    val controller = SQLController()
    controller.saveTreeToDB(test_data)
    val remTree = controller.getTree("test")

And you can save red-black tree to Neo4j database

    val tree = RedBlackTree(1, "apple")
    tree.setName("test")
    val controller = Neoj4Conroller()
    contoller.saveTree(tree)
    val remTree = controller.loadTree("test")

An example of interacting with trees through a graphical interface Example gif

trees-3's People

Contributors

ancavar avatar surfaceyellowduck avatar nemakin avatar github-classroom[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.