0
我正在嘗試編寫返回具有相同標籤的所有節點的路徑的JAVA代碼。Java從根搜索具有相同標籤的所有節點路徑
在image specified in link。我應該得到以下O/P爲標籤Ç
A-> B
甲
作爲輸出。
我知道所有可能的標籤。說標籤的範圍可以從A到J.
樹的節點類:
class Node{
String label;
int count;
List<Node> children;
public int hashCode() {
return label.hashCode();
}
public boolean equals(Object obj) {
Node other = (Node)obj;
return other.label.equals(label);
}
}
我試圖像
for(each label)
start from root
search for all possible label location
print path for each label location
但不能什麼瞭解如何編寫代碼。請幫忙。
非常感謝。代碼對我來說工作得很好。 我寫簡單printPath功能 私人無效printPath(列表路徑) { 對(INT I = 0; I
2013-03-20 06:08:05