Maybe something like this?
import java.util.*;
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.
Jon Emerson
Adobe Systems, Inc.
http://www.jonemerson.net/