我为家谱写了这个树类
现在我需要一种搜索方法来在我的树中找到一个节点
它是一个 n 叉树,每个节点可以有 0 到 n 个子节点
搜索方法可以搜索一个节点或两个名称,包括节点名称和他/她的父亲名称
请帮帮我
public class FamilyNode {
public String name;
public String sex;
public FamilyNode Father;
public FamilyNode Mother;
public FamilyNode Spouse=null;
public String status="alive";
public int population;
public ArrayList<FamilyNode> children=new ArrayList<FamilyNode>() ;
public FamilyNode(String name1,String sex1){
this.name=name1;
this.sex=sex1;
this.population=this.children.size()+1;
}
public void SetParents(FamilyNode father,FamilyNode mother){
this.Father=father;
this.Mother=mother;
}
public void SetHW(FamilyNode HW){
this.Spouse=HW;
}
public void AddChild(FamilyNode child){
child.SetParents(this.Father, this.Spouse);
this.children.add(child);
this.Spouse.children.add(child);
}
public int Number (){
int number_of_descendants = this.population;
if(this.Spouse!=null) number_of_descendants++;
for(int index = 0; index < this.children.size(); index++)
number_of_descendants = number_of_descendants+ this.children.get(index).Number();
return number_of_descendants;
}
}