See also red/black tree set, that support many types.
There is C++ class for red/black tree, that have method for console output for tree without any specific libraries. The program correctly outputs numbers with any number of digits.
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 rbtree.cpp -o main
./mainThe following methods are available for working with tree:
void RBTree::insert(const int value): inserts node with valuevalueto a tree and calls the fixup function.void RBTree::erase(const int value): erases the node with valuevaluefrom tree and calls the fixup function.int RBTree::max() const: returns maximum value in the tree.int RBTree::min() const: returns minimum value in the tree.RBTree::Node *find(const int value) const: returns a pointer to a node in the tree with the valuevalue.void RBTree::clear(): erases all the nodes from the tree.ostream &operator<<(ostream &out, const RBTree &tr): outputs the tree to the ostream. IfRBTree::show_null_leavesistrue(falseby default) it displays null leaves.
With null leaves:

