我需要一棵樹/向無環圖的實現是這樣的:樹(向無環圖)實現
public class TreeNode<K, V> {
private K key; // 'key' for this node, always present
private V value; // 'value' for this node, doesn't have to be set
private TreeNode<K, V> parent;
private Set<TreeNode<K, V>> children;
}
- 沒有任何形式的排序。
TreeNode
只是一個圍繞密鑰和可能值的包裝(節點不必設置值)。- 我需要父母和孩子的鏈接。
標準API或Commons等有什麼可以做到這一點嗎?
我不介意自己寫(我肯定是不是問你們鄉親)我只是不想重新發明輪子。
要小心,樹和有向無環圖不是同一回事,對於有向無環圖,這是父親的簽名:`private Set>`,因爲一個節點可以有多個父母。 –
jolivier
2012-08-30 13:10:52