0
コードで何が間違っていると指摘できますか?私が観察したところから、戻り値のルートは正常に動作しません。以下のようにJava:再帰的な深さの最初の走査
private Node find(String name, Node root)
{
if (root != null)
{
if (root.name.equals(name)){
System.out.println(root.name);
return root;
}
find(name, root.father);
find(name, root.mother);
System.out.println(root.name + "This");
}
return null;
}
public void addParents(String ego, String father, String mother)
{
Node temp = find(ego);
if (temp == null)
throw new IllegalArgumentException("No such name.");
temp.father = new Node(father, null, null);
temp.mother = new Node(mother, null, null);
System.out.println(temp.name + " | " + temp.father.name + " | " + temp.mother.name);
}
'root.father'と' root.mother' ...これは非常に奇妙なツリー構造です。 –