public Node Clone() { var newNode = new Node() { Character = Character, LeftChild = LeftChild?.Clone(), MiddleChild = MiddleChild?.Clone(), RightChild = RightChild?.Clone(), Parent = Parent, Key = Key, Value = Value }; if (newNode.LeftChild != null) { newNode.LeftChild.Parent = newNode; } if (newNode.MiddleChild != null) { newNode.MiddleChild.Parent = newNode; } if (newNode.RightChild != null) { newNode.RightChild.Parent = newNode; } return(newNode); }
/// <summary> /// Creates a clone of the current instance of the tree node. /// </summary> /// <returns>A cloned instance of the tree node.</returns> public object Clone() { BinaryTreeNode clone = new BinaryTreeNode(); if (_value is ICloneable) { clone.Value = (IComparable)((ICloneable)_value).Clone(); } else { clone.Value = _value; } if (LeftChild != null) { clone.LeftChild = LeftChild.Clone() as BinaryTreeNode; } if (RightChild != null) { clone.RightChild = RightChild.Clone() as BinaryTreeNode; } return(clone); }
/// <summary> /// Returns a cloned copy of the node, deep-cloning all data. This will throw an exception for a null node. /// </summary> public Node Clone() { // To clone it, we copy Character, Parent, Key and Value onto a new instance and then clone the child nodes (if non-null). After this the // Parents on the child nodes will have to be set to the new instance so that a new chain can be formed. This should be called against // the root node such that an entirely new tree is formed. var newNode = new Node() { Character = Character, LeftChild = (LeftChild == null) ? null : LeftChild.Clone(), MiddleChild = (MiddleChild == null) ? null : MiddleChild.Clone(), RightChild = (RightChild == null) ? null : RightChild.Clone(), Parent = Parent, Key = Key, Value = Value }; if (newNode.LeftChild != null) { newNode.LeftChild.Parent = newNode; } if (newNode.MiddleChild != null) { newNode.MiddleChild.Parent = newNode; } if (newNode.RightChild != null) { newNode.RightChild.Parent = newNode; } return(newNode); }
public TreeNode Clone() { return(new TreeNode { Value = Value, Parent = Parent == null ? null : Parent.Clone(), LeftChild = LeftChild == null ? null : LeftChild.Clone(), RightChild = RightChild == null ? null : RightChild.Clone() }); }
/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public virtual object Clone() { return(new InnerDawgNode <TKey, TValue>() { Key = Key, LeftChild = LeftChild == null ? null : (IDawgNode <TKey, TValue>)LeftChild.Clone(), RightSibling = RightSibling == null ? null : (IDawgNode <TKey, TValue>)RightSibling.Clone(), }); }
/// <summary> /// ICloneable implementation /// </summary> /// <returns></returns> public object Clone() { BinaryTreeNode <T> clone = new BinaryTreeNode <T>(Value); if (LeftChild != null) { clone.LeftChild = (BinaryTreeNode <T>)LeftChild.Clone(); } else { clone.LeftChild = null; } if (RightChild != null) { clone.RightChild = (BinaryTreeNode <T>)RightChild.Clone(); } else { clone.RightChild = null; } return(clone); }
public override TreeNode Clone(TreeNode parent = null) { return(new BinaryOperationTreeNode(Operation, LeftChild.Clone(this), RightChild.Clone(this), parent)); }
/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public override object Clone() { return(new EndLinkedDawgNode <TKey, TValue>(Key, LeftChild == null? null: (IDawgNode <TKey, TValue>)LeftChild.Clone(), RightSibling == null? null: (IDawgNode <TKey, TValue>)RightSibling.Clone(), Value)); }
/// <summary> /// Creates a deep copy of the numeric expression. /// </summary> /// <returns>Numeric expression clone.</returns> public INumericExpression Clone() { return(new Minus(LeftChild.Clone(), RightChild.Clone())); }
/// <summary> /// Creates a deep copy of the expression. /// </summary> /// <returns>Expression clone.</returns> public IExpression Clone() { return(new ImplyExpression(LeftChild.Clone(), RightChild.Clone())); }