本文介绍了删除整个二进制搜索树的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道删除整个二进制搜索树的最有效方法.也不要让任何内存泄漏,因此必须先检查子树中的所有节点是否都被删除.
I would like to know the most efficient way to delete an entire binary search tree. also not to let any memory leak so having to check if all the nodes in the sub trees are deleted first.
除了后遍历遍历,我想不出任何有效的方法,可以随时删除.有什么建议或想法吗?
I cant think of any efficient way besides post order traversal, deleting as you go. any suggestions or ideas?
推荐答案只需将您的根节点设置为null.让垃圾收集器完成其工作.
Just set your root node as null. Let the garbage collector to do its job.
更多推荐
删除整个二进制搜索树的最有效方法
发布评论