title: I have two binary trees. I wanted to deep copy the result of the two binary trees without changing the input trees
body: <pre><code>class Node{
  public:
  friend class BinaryTreeAdd;
  Node(int value, Node* left, Node* right)
  {
      this-&gt;value = value;
      this-&gt;left = left;
      this-&gt;right = right;
  }
   int getValue() const
  {
      return value;
  }
  
  Node* getLC() const
  {
      return left;
  }
  
  Node* getRC() const
  {
      return right;
  }
  void setValue(int value) {
      this-&gt;value = value;
  }
  void setLC(Node* left) {
      this-&gt;left = left;
  }
  void setRC(Node* right) {
      this-&gt;right = right;
  }
   public:
     int value;
     Node* left;
     Node* right;
   };
  class class BinaryTreeAdd {
   public:
  static Node* cpNode(const Node* source)
  {
      if (source == nullptr)
      {
          return nullptr;
      }
      return source == nullptr? nullptr
             : new Node(source-&gt;value,
              cpNode(source-&gt;left),
              cpNode(source-&gt;right));
  }
   static Node* add(Node *t1, Node *t2){
      if (t1 == NULL) {
           return t2;
      }
      if (t2 == NULL) {
           return t1;
      } 
      t1-&gt;value += t2-&gt;value;
      t1-&gt;left=add(t1-&gt;left, t2-&gt;left);
      t1-&gt;right=add(t1-&gt;right, t2-&gt;right);
      return t1;
  }
  void display(Node * node){
      while (node != NULL) {
          cout &lt;&lt; node-&gt;getValue() &lt;&lt; endl;
              display(node-&gt;getLC());
              display(node-&gt;getRC());
          return;
      }
  }
  };
  int main(){
  BinaryTreeAdd bt;
  Node root1(3, NULL, NULL);
  Node root2(1, &amp;root1, NULL);
  Node root3(3, NULL, NULL);
  Node root4(5, &amp;root2, &amp;root3);
  
  Node root5(5, NULL, NULL);
  Node root6(6, NULL, &amp;root5);
  Node root7(5, NULL, NULL);
  Node root8(2, &amp;root6, &amp;root7);
  
  Node *root9 = BinaryTreeAdd::add(&amp;root4, &amp;root8);
  Node *root10 = BinaryTreeAdd::cpNode(root9);
  bt.display(root10);
  return 0;
  }
  </code></pre>
  <ol>
  <li>I have merged two trees t1 and t2 and stored the results back in t1
  (add function).
  Function call: Node *root9 = BinaryTreeAdd::add(&amp;root4, &amp;root8);</li>
  <li>Then I have deep copied the t1 to source (cpNode function).
  Function call: Node *root10 = BinaryTreeAdd::cpNode(root9);</li>
  <li>I have used a display function to print the results of the deep copy.
  Function call: bt.display(root10);</li>
  </ol>
  <p>My question is:</p>
  <blockquote>
  <ol>
  <li><p>How should I copy the contents of t1 and t2 directly to the source node using cpNode function?</p>
  </li>
  <li><p>Contents of t1 and t2 should not be changed after merging the trees.</p>
  </li>
  </ol>
  </blockquote>