Solved

building tree recursively *urgent*

Posted on 2004-04-13
3
165 Views
Last Modified: 2010-03-31
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~
                  
     }
}
0
Comment
Question by:jtcy
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 500 total points
ID: 10820744
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 Comment

by:jtcy
ID: 10820874
don understand at all
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10820908
Did you have a look on processHierarchy(... method
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now