recursion - Recursive Insertion in a Binary Tree C# -


why reason member variables left , right never change when make recursive call? here's source code:

public class c_nodo  {     int dato;     c_nodo left;     c_nodo right;      public int dato     {         { return dato; }         set { dato = value; }     }      public c_nodo left     {         { return this.left; }         set { this.left= value; }     }      public c_nodo right     {         { return this.right; }         set { this.right = value; }     }      public c_nodo(int inf)     {         this.dato = inf;         this.left = null;         this.right = null;     } }  public class c_arbol_bin  {        c_nodo root;      public c_arbol_bin()     {         root = null;     } 

simple insertion in root or make recursive call

    public void inserta(int dat)     {         if (root == null)         {             root = new c_nodo(dat);         }         else         {             insert_order(this.root, dat);         }     } 

here make recursive insertion in ordered way depending of value contains father node righ , left never change.

    public void insert_order(c_nodo tree, int inf)     {         if (tree == null)         {             tree = new c_nodo(inf);         }         else         {             if (tree.dato > inf)             {                 insert_order(tree.left, inf);             }             else             {                 insert_order(tree.right, inf);             }         }     } } 

thanks help.

declare function like

public void insert_order( ref c_nodo tree, int inf ); 

also function auxiliary function function inserta declared private


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -