Skip to content

Console colored output for red/black tree set in C++ without any specific libraries

Notifications You must be signed in to change notification settings

mickleon/rbtree-set-visualization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Red/black tree set visualisation

What is this?

There is C++ class for red/black tree set, that have method for console output for tree without any specific libraries. The program correctly outputs all types, that can be output using the << operator.

What is it for?

This is a training example of a red/black tree. This may be necessary for those who study C++ and dynamic structures such as trees.

Run

make
./main

or

g++ main.cpp -o main
./main

Available features

RBTree<T> is a template class that supports all types, that are comparable and can be output using the << operator.

The class supports iteration, so the tree elements can be iterated through in a loop:

RBTree<int> tr;
for (int el : tr) {
    cout << el << ' ';
}

The following methods are available for working with tree:

  • void RBTree<T>::insert(const T value): inserts node with value value to a tree and calls the fixup function.
  • void RBTree<T>::erase(const T value): erases the node with value value from tree and calls the fixup function.
  • int RBTree<T>::max() const: returns maximum value in the tree.
  • int RBTree<T>::min() const: returns minimum value in the tree.
  • void RBTree::clear(): erases all the nodes from the tree.
  • ostream &operator<<(ostream &out, const RBTree<T> &tr): outputs the tree to the ostream. If RBTree::show_null_leaves is true (false by default) it displays null leaves.
  • Iterator RBTree<T>::begin() const: returns an iterator to the element with the minimal value.
  • Iterator RBTree<T>::end() const: returns an iterator to the element which is after the element with the maximum value (nullptr).

Example of output

Tree output

With null leaves:

Tree output with null leaves

With std::string nodes:

Output of a tree with string nodes

About

Console colored output for red/black tree set in C++ without any specific libraries

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors