foldtraverse.cpp

The following code example is taken from the book
C++17 - The Complete Guide by Nicolai M. Josuttis, Leanpub, 2017
The code is licensed under a Creative Commons Attribution 4.0 International License. Creative Commons License


#include "foldtraverse.hpp"
#include <iostream>

int main()
{
  // init binary tree structure:
  Node* root = new Node{0};
  root->subLeft = new Node{1};
  root->subLeft->subRight = new Node{2};
  //...
  // traverse binary tree:
  Node* node = Node::traverse(root, Node::left, Node::right);
  std::cout << node->getValue() << '\n';
  node = root ->* Node::left ->* Node::right;
  std::cout << node->getValue() << '\n';
  node = root -> subLeft -> subRight;
  std::cout << node->getValue() << '\n';
}