java - Recursive Insert for Binary Tree -


I am working on code for inclusion in a binary search tree. This works for the first node which I insert, it creates a root, but after that it does not include any nodes. I'm sure that this is a problem in setting left / right references, but I can not understand this much please help!

  // params: enter the key of the node, enter the parent node public zero (int NewKey, tree node parent) {// If the root of the tree is empty, then insert the root (if this is. GetRoot () == faucet) {this.root = new TreeNode (newKey, null, null); } // If the node is empty, then insert it on this node and if (parent == zero) parent = new tree node (new, faucet, empty); Else {// If the value is lower than the value of the current node, put it on the left child of the node, then call (Newkele  parent.getKey ()) {insert (newkey, parent.getRight ()); } // Similar to the value of the current node, increment by frequency field if another (newKey == parent.getKey ()) parent.incrementIterations (); }}   

In my treenodes there are keys, left, right and repeat fields, as well as gate / setter functions. Thank you very much in your advance! Public node lockdown (node ​​head, int data) {if (head == empty)

  {Head = new node (); Head.data = data; Return head; } If (headdata & lt; data) {head.right = insertNode (head.right, data); } And {head.left = insertNode (head.left, data); } Return head; }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -