선행 검색을 사용하여 az와 AZ 문자로 구성된 이진 트리에서 노드를 찾으려고합니다. 여기서 왼쪽은 "0"으로 표시되고 오른쪽으로가는 것은 "1"로 표시되어 올바른 출력은 왼쪽에 두 개의 분기 인 노드에 대해 "00"처럼 보일 것입니다. 노드는 정렬되지 않습니다.바이너리 트리의 특정 노드에 인쇄
static String routeNum = "";
private static String onePath(BinaryNodeInterface<Character> root, String route) {
BinaryNodeInterface<Character> temp = root;
if(temp != null){
if(temp.hasLeftChild()){
routeNum = onePath(temp.getLeftChild(),route+"0");
}
if(temp.hasRightChild()){
routeNum = onePath(temp.getRightChild(), route+"1");
}
}
System.out.print(route);
return route;
}
출력 내가 바로 노드에 얻고 있음을 나타냅니다하지만 경로를 인쇄하지 않습니다
지금까지 나는이 있습니다.
이 함수. – splrs
'routeNum = route + "0"; onePath (temp.getLeftChild(), route + "0"); ' 'routeNum = route + "1"; \t onePath (temp.getRightChild(), route + "1")); 이것을 할 수있는 깨끗한 방법은 StringBuffer를 사용하는 것입니다. – arunmoezhi