Java BasicsGeneral beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Java Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
I want to create a tree data structure [not binary tree nor JTree] with unlimited branch and I can go in each branch in that tree. Anyone can give me an example? or URL link..
public class NaryTree
{
private ArrayList children = new ArrayList();
private Object value;
public NaryTree(Object value)
{
this.value = value;
}
public NaryTree getChild(int n)
{
return (NaryTree)children.get(n);
}
public void putChild(int n, NaryTree child)
{
children.add(n, child);
}
public Object getValue()
{
return value;
}
public void setValue(Object value)
{
this.value = value;
}
}
Of course, this is basically just an ArrayList with a value associated with it. So you could just extend ArrayList, add the value getter and setter, and have your N-ary tree. But the code might be a little harder to understand without some good Javadocs.