1

I'm looking at the same tree traversal example as THIS POST. My VS is not supporting C++17 to see Fold Expresion inner workings. I guess this line:

Node* node = traverse(root, left, right);

would only traverse the binary tree from the root to the first leaf node and return? Or is it a complete preorder traversal?
How to implement Pre- Post- and Inorder traversals using Fold Expressions?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
user2376997
  • 501
  • 6
  • 22
  • 4
    That `traverse` isn't actually a traversal. It follows the path `left, right` (or whatever you pass it) inside `root` and returns the `Node*` at that position. I might call it `index`. – HTNW Jul 21 '20 at 15:18
  • 2
    Fold expressions are best used when there is a large number of operations whose order is fixed at compile time. Trees are usually dynamic. So I'm not sure what you want here. – Yakk - Adam Nevraumont Jul 21 '20 at 20:59
  • Have you set your compiler to latest standard? – Phil1970 Jul 22 '20 at 00:42

0 Answers0