jtcy
asked on
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);
aNode.addChild(child1);
aNode.addChild(child2);
current_level++;
int temp = buildGameTree(s.getChild(0 ),d);
int temp2 = buildGameTree(s.getChild(1 ),d);
//stuck here~
}
}
int buildGameTree(GameTreeNode
{
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);
aNode.addChild(child1);
aNode.addChild(child2);
current_level++;
int temp = buildGameTree(s.getChild(0
int temp2 = buildGameTree(s.getChild(1
//stuck here~
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you have a look on processHierarchy(... method
ASKER