开发者

how to recursively delete all nodes in JTree?

开发者 https://www.devze.com 2023-03-22 18:00 出处:网络
in a JTree comprised of DefaultMutableTreeNodes, how would you traverse and delete starting from a given Node and all it\'s ancestors?

in a JTree comprised of DefaultMutableTreeNodes, how would you traverse and delete starting from a given Node and all it's ancestors?

it should开发者_如何学编程 delete starting at it's deepest level , backing upwards to the given Node. the given starting node should be the last thing to remove.


Recursion is your friend here.

In pseudo code:

def deleteTree(root)
    for each child c of root
        deleteTree(c)
    end
    delete root
end
0

精彩评论

暂无评论...
验证码 换一张
取 消