title: Post order traversal of a tree
body: <p>I try to do a post post order traversal of a tree. The nodes of the the tree have an int data and 2 pointers one left and one right. I have a function that gives me the head of the tree. What I do is:
  I create a temporary node and set it to be the head. Than what I ant to do is to iterate to the tree until this temp becomes nullptr. So in each iteration I check if there is a right or left pointer to the node and set the temp accordingly. If the node has no left or right pointers I get the value of the node and ad it to a vector. Than I need to delete this node (and here is the problem) and make again the temp to point to the root of the tree. My problem is I think that I can't delete the last node. Here is my code.</p>
  
  <pre><code>void postOrder(Node* root)
  {
      vector&lt;int&gt; result;
      Node* tmp = nullptr;
      tmp = root;
      int val = 0;
  
      while ((tmp != nullptr)) {
  
          if (tmp-&gt;left != nullptr) {
              tmp = tmp-&gt;left;
          }
          else if (tmp-&gt;right != nullptr) {
              tmp = tmp-&gt;right;
          }
          else {
              val = tmp-&gt;data;
              cout &lt;&lt; val;
              result.push_back(val);
              *tmp = NULL;
              tmp = root;
          }
      }
      for (auto&amp; e : result)
          cout &lt;&lt; e &lt;&lt; " ";
  }
  </code></pre>
  
  <p>I try to set to null what this temp pointer is pointing too and then set it again to the head but that didn't work;</p>