Exemple #1
0
 public NodeCopy(int val = 0, NodeCopy left = null, NodeCopy right = null, NodeCopy random = null)
 {
     this.val    = val;
     this.left   = left;
     this.right  = right;
     this.random = random;
 }
Exemple #2
0
 public void DFS(Node node, NodeCopy copy)
 {
     if (node == null)
     {
         return;
     }
     copy.random = node.random == null ? null : dict[node.random];
     DFS(node.left, copy.left);
     DFS(node.right, copy.right);
 }
Exemple #3
0
        public NodeCopy CopyNode(Node node)
        {
            if (node == null)
            {
                return(null);
            }
            var copy = new NodeCopy(node.val);

            dict[node] = copy;
            copy.left  = CopyNode(node.left);
            copy.right = CopyNode(node.right);
            return(copy);
        }