A simple C++ utility to generate images of binary search trees using SFML 2.
A Larege Red Black Tree. A Large Splay Tree An unbalanced BST and Left Leaning Red Black Tree UPDATE: As of 1/2024 node labeling, and tiling have been aded, so capturing sequences of insertions, etc is much easier.
-TreeDraw.hpp -the tree visualizer.
-treeviz.cpp - an example of how to use TreeDraw with the trees listed below.
-redblack.hpp - example RedBlack And Left Leaning Red Black Tree.
-avl.hpp - example AVL Tree.
-bst.hpp - unbalanced recursive Binary Search Tree
-treenode.hpp - node type used by above trees.
TreeDraw works by performing two traversals of a binry tree in. The first pass is an in-order traversal which calculated each nodes x/y coordinates. A second, breadth-first (level order) traversal is then performed to pair up the nodes point coordinates for the edges which connect the vertices to its children. The result is a graphical representation of the tree, which is both displayed to the screen and also saved in the current working directory as tree.jpg
Right now the code depends on you using the supplied treenode.hpp as the node for the binary tree you're building. In the future I plan to remove this dependency, possibly with the visitor pattern. Instantiate a TreeDraw object, and when you have the tree you wish to depict, you use the mark(root, nullmarker, treetype) method to perform a traversal of the tree, and then invoke drawTree().
int main() {
TreeDraw<int,int> td;
RedBlackTree<int,int> bst;
for (int i = 0; i < 10; i++) {
bst.insert(rand() % 50, i);
td.mark(bst.rootNode(), nullptr, REDBLACK)
}
td.drawTree();
}