recursion - Rebuild BST from preorder, error in logic -


I'm trying to wrap my head to correct my code, but I get stuck during the implementation I go.

When I step down through the code given below, then I can reinstate the BST portion from the pre-order traveler. But at some point, I will be like a function call:

  recon (preOrd, 2,2)  

resulting in not identifying a leaf is. I still know how to fix it.

I have seen other threads on this subject but want to exclude my problem, so I can actually learn this concept of rebuilding the BST.

  public static node recon (int [] preOrd, int start, int end) {if (start == end) {return null; } Node root = new node (preOrd [start]); Int div = start; (I = Start + 1; i & lt; = End & Preord [i] & lt; preOrd [Start]; i ++) {div = i; } Node left = rebuilding (pre-start, + 1, div); Node correct = rebuilding (previously, div + 1, end); Root.setLeft = left; Root.setRight = true; Return route; } It is very easy to get out, updating the lead nodes, correcting my thinking.  

  public static node recon (int [] preOrd, int start, int end) {node root = new node (preOrd [start]); // Announce the new node if (start> end) {// it is illegal, so empty return zero; } If (start == end) {return route; } Int div = start; (IntitI = Start + 1; I & lt; = & Preord [i] & lt; Preord [Start]; i ++) {div = i; } Node left = rebuilding (pre-start, + 1, div); Node correct = rebuilding (previously, div + 1, end); Root.setLeft = left; Root.setRight = true; Return route; }  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -