Forums | Hello Guest, Login or Register | > > L4Y Files: No longer here! < <
  Levels-4-You : Lounge : Recursive Tree Building [Forum Rules]  


Back to Forum Thread List

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-
... War of the masses, the outcome, disastrous,
Many of the victim family save they ashes ...
 
 Modified Nov 3rd, 09:39pm by Tech_N9ne



Copyright © 2000-2025 Levels-4-You
Your request was handled in 0.05 seconds.