Hi, Where can I find the example of Tree structure using JAVA ?
I would like to do a family tree by using Java. but I have no idea.
Thanks.
Printable View
Hi, Where can I find the example of Tree structure using JAVA ?
I would like to do a family tree by using Java. but I have no idea.
Thanks.
You could implement this using a simple class structure:
Obviously you will need to implement the getters and setters for the lists but that will allow you to construct your family tree. Also you may wish to limit the parent list to 2 entries or change this for :Code:public class Person {
private List<Person> parents;
private List<Person> children;
...
public void addParent(Person parent) {
this.getParents().add(parent);
parent.getChildren().add(this);
}
public void addChild(Person child) {
this.getChildren().add(child);
child.getParents().add(this);
}
}
instead.Code:private Person mother;
private Person father;
Hope this gets you started. :)
Can a get a code to print a tree diagem using java