title: Copying a binary tree
body: <p>When asked to create a copy of the binary tree, I have always been told to use a post order traversal logic to make the copy. </p>
  
  <p>Is it not possible to process the original tree in pre-order or in-order to create a copy?</p>
  
  <p>Any traversal method more optimal than the other?</p>
  
  <p>Post-order way:</p>
  
  <pre><code>NODEPTR Copy(NODEPTR p)
  {
    if (p == null) return p
    NODEPTR left = Copy(p-&gt; left)
    NODEPTR right = Copy(p-&gt; right)
    NODEPTR root = MakeBT(p-&gt;data, left, right) //MakeBT is a helper function that makes a tree
    return (root)
  }
  </code></pre>
  
  <p>Pre-order way:</p>
  
  <pre><code>NODEPTR Copy(NODEPTR p)
  {
    if (p == null) return p
    NODEPTR root
    root-&gt;data = p-&gt;data
    root-&gt; left = Copy(p-&gt; left)
    root-&gt; right = Copy(p-&gt; right)      
    return (root)
  }
  </code></pre>
  
  <p>In-order way:</p>
  
  <pre><code>   NODEPTR Copy(NODEPTR p)
      {
        if (p == null) return p
        NODEPTR left = Copy(p-&gt; left)
        NODEPTR root
        root-&gt; data = p-&gt; data
        root-&gt; left = left
        root-&gt; right = Copy(p-&gt; right) 
        return (root)
      }
  </code></pre>