In fancy_tree.hpp line:9 include the header file with the definition of your node (test.hpp in our case).
//header file that contains Node definition
#include "test.hpp"Replace the flowing macros according to your Node definition fancy_tree.hpp line:20
// Node class
#define NODE Node<T>
// Node class attributes
#define LEFT _left // left attribute
#define RIGHT _right // right attribute
#define PARENT _parent // parent attribute (can be ignnored)
#define CONTENT _value // data attribute + element of pair(if exists)According to this defnition in our test file test.hpp
template <typename T>
class Node {
public:
T _value;
Node<T> *_left;
Node<T> *_right;
Node<T> *_parent;
Node(T value)
{
this->_value = value;
this->_left = nullptr;
this->_right = nullptr;
this->_parent = nullptr;
}
};By running the following test test.cpp
int main()
{
Node<int> *root = new Node<int>(38);
root->_left = new Node<int>(26);
root->_right = new Node<int>(70);
root->_left->_left = new Node<int>(6);
root->_left->_right = new Node<int>(15);
root->_right->_left = new Node<int>(43);
root->_right->_right = new Node<int>(88);
root->_left->_left->_left = new Node<int>(3);
root->_left->_left->_right = new Node<int>(15);
root->_left->_right->_left = new Node<int>(27);
root->_left->_right->_right = new Node<int>(36);
root->_right->_left->_left = new Node<int>(40);
root->_right->_right->_left = new Node<int>(85);
root->_right->_right->_right = new Node<int>(89);
root->_left->_left->_right->_left = new Node<int>(12);
// construct and object of type FancyTree
fancy_tree<int> tree;
// to print in a vrtical view (root on the top mid of the tree)
tree.print_tree(root, V_VIEW);
// to print in a horizontal view (root on the left mid of the tree)
tree.print_tree(root, H_VIEW);
}- Vertical view
print_tree(root, V_VIEW);
ββββββ
βββββββββββββββββββββββββββββ€ 38 βββββββββββββββββββββββββββββ
β ββββββ β
β β
βββββ΄β ββ΄ββββ
βββββββββββββ€ 26 βββββββββββββ βββββββββββββ€ 70 βββββββββββββ
β ββββββ β β ββββββ β
β β β β
βββββ΄β ββ΄ββββ βββββ΄β ββ΄ββββ
βββββ€ 6 βββββ βββββ€ 15 βββββ βββββ€ 43 β βββββ€ 88 βββββ
β ββββββ β β ββββββ β β ββββββ β ββββββ β
β β β β β β β
βββββ΄β ββ΄ββββ βββββ΄β ββ΄ββββ βββββ΄β βββββ΄β ββ΄ββββ
β 3 β βββ€ 15 β β 27 β β 36 β β 40 β β 85 β β 89 β
ββββββ β ββββββ ββββββ ββββββ ββββββ ββββββ ββββββ
β
βββ΄βββ
β 12 β
ββββββ
- Horizontal view
print_tree(root, H_VIEW);
ββββ€89
ββββ€88
β ββββ€85
ββββ€70
β ββββ€43
β ββββ€40
βββ€38
β ββββ€36
β ββββ€15
β β ββββ€27
ββββ€26
β ββββ€15
β β ββββ€12
ββββ€6
ββββ€3
