本文介绍了如何从Lisp中的二叉搜索树中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从BST删除节点?

How can I delete a node from a BST?

我需要一种算法来在Scheme博士中做到这一点.

I need an algorithm to do that in Dr. Scheme.

推荐答案

基本上,您会丢掉现在拥有的BST,并在没有该元素的情况下创建一个新的BST.

You basically toss the BST you have now, and create a new one sans the element.

您可以通过递归下降树来做到这一点.如果您的项目小于根基准,请创建一个BST,该BST的根和大于分支将从您现在拥有的副本复制而来,但其小于分支是递归调用的结果.

You can do this by recursively descending the tree. If your item is less than the root datum, create a BST whose root and greater-than branch is copied from what you have now, but whose less-than branch is the result from a recursive call.

这与添加节点的方式非常相似,但是当您找到要搜索的节点时,将其下面的两个BST合并并返回结果.当然已经存在有关如何执行此操作的问题.

It's very similar to how you add a node, but when you get to the one you were searching for, merge the two BSTs below it and return the result. There are surely existing questions about how to do that already.

这篇关于如何从Lisp中的二叉搜索树中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:12