Binary Tree Search Node Method using recursion JAVA -
hi sample tree
---------e -------d----g ----b------f--t ---a--c--------z   so if node string class. , trying find f. need start searching possible right nodes first, search in left nodes match incoming string
this have far
public node search (string string)    if(this.name.isequalto.string)      return this;    else       if(this.next!=null)        return this.getright().search;   i not sure how make code go in 3 , search left.
you there: make code search both subtrees, not return search of this.getright unless item found. instead, search left subtree, this:
if (this.getright() != null) {     node res = this.getright().search(string);     if (res != null) {         return res;     } } if (this.getleft() != null) {     return this.getleft().search(string); } return null;      
Comments
Post a Comment