I'm a newbie in Java. I want to build a tree with one root node and multiple children nodes with some weight on each branch. Can somebody help me in this.
+2
A:
This is just a sketch to get you started, and could be improved a lot. But your basic members could be as follows:
public class WeightedTree {
private double weight;
private List<WeightedTree> children;
}
I don't want to write more in case it's a homework question, but if you have specific follow up feel free to comment.
Nick Fortescue
2009-02-23 10:58:10
While functional, I think it's not a good idea to name node objects as trees... so maybe call it WeightedTreeNode instead?
StaxMan
2009-09-08 06:57:56
+4
A:
Sample code:
class Node {
public int weight;
public List<Node> children = new ArrayList<Node> ();
}
Node root = new Node ();
Aaron Digulla
2009-02-23 11:01:26
A:
Hi, Are there any classes that are used for tree building and that can be imported? I too want to create a tree using Java!
fixxxer
2009-09-08 06:54:49