I have n-ry tree with node like this:
class Node
{
public Node Parent = null;
public List<Node> Children = new List<Node>();
public string Name;
}
I need to do a deep copy of original tree and avoid changing of new tree when original tree is changed. I know only how to do shallow copy:
public Node Copy(Node original)
{
Node newNode = new Node();
newNode.Parent = original.Parent;
newNode.Children = original.Children;
newNode.Name = original.Name;
return newNode;
}
In this case I copy both Nodes point to on object in memory and when original node changed a newNode will be changed to. Could anyone help me to do deep cloning?