Code Monkey home page Code Monkey logo

red-black-tree's Introduction

Implementation of Red-Black tree

This is the implementation of Red-Black tree on C++17. Here you can find template class rb_tree in namecpase TepNik.

This class supports move-semantics and also it is exception safe.

Also here you can find file for unit-testing in Visual Studio (CppUnitTestFramework).

Public interface

Template class rb_tree<Key_type, Value_type>

Constructor(default, copy, move) and destructor.

rb_tree()
rb_tree(const rb_tree &sec)
rb_tree(rb_tree &&sec) noexcept
~rb_tree()

Erase function.

void erase(const Key_type &key)

Insert function.

void insert(Key_type key, Value_type value)

Copy and move operator.

rb_tree& operator=(const rb_tree &sec)
rb_tree& operator=(rb_tree &&sec) noexcept

Equal operator.

bool operator==(const rb_tree &sec) const

Find function for const and non-const containers. Returns pointer to the value of this key if it is in the tree or nullptr if there is no such key in this tree.

const Value_type* find(const Key_type &key) const
Value_type* find(const Key_type &key)

Function that clean container.

void clear()

Functions that return vectors of all keys and values in this tree.

std::vector<Key_type> get_keys() const
std::vector<Value_type> get_values() const

Function that print tree.

void print(std::ostream &stream = std::cout, bool with_color = false) const

Tree from example

L--key:4
   value:2
   +-------key:2
   |       value:2
   │       +-------key:1
   │       |       value:2
   │       L-------key:3
   │               value:2
   L-------key:6
           value:2
           +-------key:5
           |       value:2
           L-------key:8
                   value:2
                   +-------key:7
                   |       value:2
                   L-------key:9
                           value:2
                           L-------key:10
                                   value:2

Function that swap this tree with other.

void swap(rb_tree &sec) noexcept

Function that returns number of elements in this tree.

int size() const

Example

Compile test program

    make

Run test program

    ./main

red-black-tree's People

Contributors

tepnik avatar

Stargazers

 avatar

Watchers

 avatar  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.