Forest is an open source, template library of tree data structures written in C++11.
$ git clone https://github.com/xorz57/forest.git
$ cd forest
$ mkdir build
$ cd build
$ cmake ..
$ make install
Forest is best explained through examples. The following source code generates a red black tree, inserts 7 nodes and then performs an in order traversal.
#include <forest/red_black_tree.h>
int main() {
// Generate a binary search tree for nodes of integer keys and values
forest::red_black_tree <int, int> red_black_tree;
// Insert 7 nodes in the form of a (key, value) pair
red_black_tree.insert(4,0);
red_black_tree.insert(2,0);
red_black_tree.insert(90,0);
red_black_tree.insert(3,100);
red_black_tree.insert(0,0);
red_black_tree.insert(14,0);
red_black_tree.insert(45,0);
// Perform an in order traversal
red_black_tree.in_order_traversal();
// Generate a .dot file representing the Red Black Tree
red_black_tree.graphviz("red_black_tree.dot");
return 0;
}
Forest provides an easy way to visualize tree data structures using the graphviz member function. When this function is called, a DOT file describing the data structure graph is created. In order to be able to generate an image of the graph you must install Graphviz. The generated DOT file can be feed to the dot tool (provided by Graphviz) which in turn will generate an image for the graph.
$ dot red_black_tree.dot -Tpng > red_black_tree.png
This is the graph visualization of the above example code, generated with the dot tool (provided by Graphviz).
Refer to the Quick Start Guide page for further information and examples.