我有以下结构:
Member {
String firstName;
String secondName;
Member[] children;
Member father;
}
>我必须在java中实现这个树;
>我有一个名字和一个成员的第二个名字.我需要找到从root到该节点的方法.
有谁可以帮助我吗?
这就是我所拥有的:
公共级会员{
public List children = new ArrayList<>();
public Member father = null;
public String secondName = null;
public String firstName = null;
public Member(String secondName, String firstName) {
this.secondName = secondName;
this.firstName = firstName;
}
public Member(String secondName, String firstName, Member father) {
this.secondName = secondName;
this.firstName = firstName;
this.father = father;
}
public List getChildren() {
return children;
}
public void setFather(Member father) {
this.father = father;
father.addChild(this);
}
public void addChild(String secondName, String firstName) {
Member child = new Member(secondName, firstName);
child.setFather(this);
this.children.add(child);
}
public void addChild(Member child) {
child.setFather(this);
this.children.add(child);
}
public String getSecondName() {
return this.secondName;
}
public String getFirstName() {
return this.firstName;
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public void setPrenume(String firstName) {
this.firstName = firstName;
}
public boolean isRoot() {
return (this.father == null);
}
public void deleteFather() {
this.father = null;
}
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/223319.html原文链接:https://javaforall.net
