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.
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.
make
./mainor
g++ main.cpp -o main
./mainRBTree<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 valuevalueto a tree and calls the fixup function.void RBTree<T>::erase(const T value): erases the node with valuevaluefrom 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. IfRBTree::show_null_leavesistrue(falseby 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).
With null leaves:
With std::string nodes:


