我有以下结构:
Member {
字符串第一名称;
字符串顺序名称;
Member[] children;
成员因子;
}
我必须用java实现这棵树;
有名称和成员的第二个名称。 我们需要找到从根到那个节点的方法。
有人能帮助你吗?
这就是我拥有的东西:
publiclistchildren=new ArrayList (;
公共成员father=null;
公共字符串second name=null;
公共字符串第一个名称=null;
公共成员(stringsecondname,String firstName ) )。
this.secondName=secondName;
this.firstName=firstName;
}
公共成员(stringsecondname,String firstName,Member father ) {
this.secondName=secondName;
this.firstName=firstName;
this.father=father;
}
公共列表获取标题(
return children;
}
publicvoidsetfather (成员因子)。
this.father=father;
Father.addchild(this;
}
公共语音地址(stringsecondname,String firstName ) )。
member child=new member (second name,firstName;
child.setfather(this;
this.Children.add(child;
}
公共void addchild (member child ) {
child.setfather(this;
this.Children.add(child;
}
公共字符串获取代码名称(
return this.secondName;
}
公共字符串获取悲伤的关键(() )。
return this.firstName;
}
publicvoidsetsecondname (字符串密码)。
this.secondName=secondName;
}
publicvoidsetprenume (string first name ) {
this.firstName=firstName;
}
公共布尔is root
return(this.father==null );
}
public void deleteFather
this.father=null;
}
}