Skip to content

Elliot-Roberts/tree-print

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a helper tool for printing binary trees in an easy to inspect format.
Example of output:

 ╭────────────────[5]─╮
 │                    │
[0]───────╮          [5]──────────────╮
          │                           │
    ╭────[2]─╮                     ╭─[12]─╮
    │        │                     │      │
   [0]─╮    [2]─╮           ╭────[10]    [13]─╮
       │        │           │                 │
      [1]      [4]       ╭─[7]─╮             [14]
                         │     │
                        [6]   [7]

To add to your project:

#include "treeHelper.hpp"

and compile with --std=c++17 or newer.

To use in code, you make a WrappedTree like so:

Node * my_tree = /* ... */;
WrappedTree<Node> wrapped(my_tree);

where Node is your binary tree node type.
The node is expected to have an accessable member named data that is able to be printed like so:

Node * my_node = /* ... */;
cout << my_node->data;

To pretty-print your tree, cout the WrappedTree:

WrappedTree<Node> wrapped(my_tree);
cout << wrapped;

There is also a work-in-progress "comparison" function for seeing how two trees differ:

Node * my_tree = /* ... */;
WrappedTree<Node> before(my_tree);
remove_even_nodes(&my_tree);  // example operation modifying tree
WrappedTree<Node> after(my_tree);
auto [old_tree, new_tree] = before.compare_to(after);  // returns pair of `WrappedTree`s
cout << old_tree;  // shows the tree before the operation, with removed parts highlighted with color
cout << new_tree;  // shows the tree after the operation, with the updated and new parts highlighted with color

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published