删除整个二进制搜索树的最有效方法 [英] most efficient way to delete an entire binary search tree

查看:67
本文介绍了删除整个二进制搜索树的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道删除整个二进制搜索树的最有效方法.也不要让任何内存泄漏,因此必须先检查子树中的所有节点是否都被删除.

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.

这篇关于删除整个二进制搜索树的最有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆