Tech_N9ne |
Posted 3rd Nov 2006 9:33pm |
L4Y Member Post 114 / 163
 |
So Im working on this project where we build a binary tree recursivly. (Segment Tree to be exact)
I believe everything to be in place but I just get a stack trace when the PC runs out of RAM(due to recursive calls)...heres what I have...
Code |
public static void createTree (node, min, max)
if (max == min+1)
return //base case
else
node.left = new node (min, max/2)
createTree(node.left, min, max/2)
node.right = new node (max + min/2, max)
createTree(node.right, max + min/2, max)
|
My logic...so you enter a node, if it is a unit segment this is the base case and you return. otherwise, you create left and right children and recurse into each.
I know that each(buildLeft, buildRight) work seperatly, but not when you put them together to build the tree.
If what Im trying to convey is vague >>here<< is the full assigment.
Any ideas what is going on? Whats wrong? Much Appreciated!
-Tech- |