-1
這裏是我的函數,我將它與我的樹的根節點以及要在樹內找到的字符一起種下。它成功地返回了我要搜索的字母表,但它並沒有給我元素的路徑。我是一個有點卡住任何幫助將appriciated我創建了哈夫曼樹,但我在生成代碼時遇到了問題。
公共節點traversingTree(節點根,字符串charToFind){
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;
}