title: c++ tree traversal depth
body: <p>I try to traverse a tree, depth first.
  Node has get_child() and get_sibling().</p>
  
  <p>Here is my naive approch which obv. doesnt work:</p>
  
  <pre><code>int traverseTree(const Node *node)
  {
      printf("index: %d \n", node-&gt;get_idx());
      const Node *child = node-&gt;get_child();
      const Node *sibling = node-&gt;get_sibling();
  
      if (child != NULL) {
          traverseTree(child);
  
      }
      else if (sibling != NULL)
      {
          traverseTree(sibling);
      }
  
      return 0;
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>here is how the tree is built: <a href="https://github.com/rggibson/open-pure-cfr/blob/master/betting_node.cpp#L137" rel="nofollow">https://github.com/rggibson/open-pure-cfr/blob/master/betting_node.cpp#L137</a></p>