我有以下功能修剪樹數據結構:刪除節點正確
public static void pruneTree(final ConditionTreeNode treeNode) {
final List<ConditionTreeNode> subTrees = treeNode.getSubTrees();
for (ConditionTreeNode current : subTrees) {
pruneTree(current);
}
if(subTrees.isEmpty()) {
final ConditionTreeNode parent = treeNode.getParent();
parent.removeConditionTreeNode(treeNode);
}
if (treeNode.isLeaf()) {
//this is the base case
if (treeNode.isPrunable()) {
final ConditionTreeNode parent = treeNode.getParent();
parent.removeConditionTreeNode(treeNode);
}
return;
}
}
,我想知道什麼是最好的方式修剪,這是。我目前正在獲得ConcurrentModificationExceptions,並且我讀過您可以複製該集合並刪除原始內容 - 或者從迭代器中刪除。有人可以幫助我理解爲了使這種方法起作用而需要做什麼嗎?
如果我從遞歸調用中返回一個布爾值,我看不到如何在樹的右側刪除它 – 2011-05-20 22:21:13