Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 218

# building tree recursively *urgent*

Can someone helps me to write a method that can produce a tree recursively? Has a branching factor of 2, and has a depth of 3. It should push the maximum value of both at depth 3 to its upper level, and the upper level pushes the minimum ones upper and the root decides the maximum value. I have done smth like: But it doesnt work. Can someone help???

int buildGameTree(GameTreeNode s)
{

if (current_level == 3)
{
int a = evaluate(s.getChildAt(0);
int b = evaluate(s.getChildAt(1);
if (current_level == 1)
int c = min(a,b);
else
int c = max(a,b);
return c;
}

else
{
// creating two nodes...

GameTreeNode child1 = new GameTreeNode(smth);
GameTreeNode child2 = new GameTreeNode(smth);

current_level++;

int temp = buildGameTree(s.getChild(0),d);
int temp2 = buildGameTree(s.getChild(1),d);

//stuck here~

}
}
0
jtcy
• 2
1 Solution

Commented:
Here is the example,

How do build the tree recursively.

http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JTree.html

Regards,
Muruga
0

Author Commented:
don understand at all
0

Commented:
Did you have a look on processHierarchy(... method
0

## Featured Post

• 2
Tackle projects and never again get stuck behind a technical roadblock.