내 함수는 다음과 같다. 내 트리의 루트 노드와 트리 안에있는 문자로 시드한다. 그것은 성공적으로 나에게 검색 할 알파벳을 돌려 주지만 엘리먼트에 대한 경로를 알려주지 않습니다. (노드 루트 문자열 charToFind을) 조금 도움이나는 호프만 나무를 만들었지 만 코드를 생성하는 데 문제가있다.
공공 노드 traversingTree을 appriciated 될 붙어 임 {
Node tempRoot = root;
if (root != null){
if (charToFind.equals(root.getAlphabet()))
{
//Another Point of consideration
System.out.print(root.getAlphabet());
System.out.println(": "+pathCodes);
pathCodes.clear();
return root;
}
Node result;
if ((result = traversingTree(root.leftChild, charToFind)) != null){
pathCodes.add("0");
return result;
}else
pathCodes.add("1");
return traversingTree(root.rightChild, charToFind);
}
}
pathCodes.clear();
return null;
}