How to clone a whole tree without affecting the original one?
<p>i use the solution in this link not work
<a href="http://stackoverflow.com/questions/78536/cloning-objects-in-c-sharp">Cloning objects in C#</a></p>

<p>the following code, can not copy to a new tree, mutate will affect the original tree root(root)</p>

<pre><code>                 foreach (Bag b in bag_list)
                {
                    if (b.cards.Count() == 2)
                    {
                        Node original_root = new Node();
                        original_root = (Node)root.Clone(); // copy to a new tree

                        target_list = choose_valid_target(target_list, b.cards, b.cards.Count() - 1);

                        foreach (Target t in target_list)
                        {
                            Console.WriteLine("op:" + t.op + ", label:" + t.label);

                            Node mutated_root = mutate(original_root, target_list);

                            result = "";
                            result = inorder(mutated_root, result); // get inorder
                            Console.WriteLine(result.Substring(1, result.Length - 2)); //print
                        }
                    }
                }

    public class Node : System.Object, ICloneable
    {
        public int priority;
        /*
        7 alphabet
        6 (,)
        5 *,/,%
        4 +,-
        3 &lt;,&lt;=,&gt;,&gt;=
        2 &amp;&amp;,||
        1 =
         */
        public string Data;
        public Node Left;
        public Node Right;
        public string Label;

        public object Clone()
        {
            //return this as object; 
            return this.MemberwiseClone(); 
            //return new Node() as object;
        }
    }

        public Node mutate(Node root, List&lt;Target&gt; targets) // mutate
        {
            if (root != null)
            {
                if (!IsLeaf(root.Left.Data))
                    mutate(root.Left, targets);

                foreach (Target target in targets)
                {
                    if (root.Label == target.label)
                    {
                        root.Data = target.op;
                    }
                }

                if (!IsLeaf(root.Right.Data))
                    mutate(root.Right, targets);
            }
            return root;
        }
</code></pre>
