java - How to deep copy a tree? -


i using own node class implement tree structure in java. i'm confused how deep copy copy tree.

my node class this:

public class node{ private string value; private node leftchild; private node rightchild; .... 

i'm new recursion, there code can study? thank you!

try

class node {     private string value;     private node left;     private node right;      public node(string value, node left, node right) {         this.value = value;         ...     }      node copy() {         node left = null;         node right = null;         if (this.left != null) {             left = this.left.copy();         }         if (this.right != null) {             right = this.right.copy();         }         return new node(value, left, right);     } } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -