这个伪代码是什么意思? - 二叉搜索树后继函数

发布于 2024-08-23 02:54:29 字数 398 浏览 0 评论 0原文

if right[x] != NIL
 then return TREE-MINIMUM(right[x])

 y<-p[x]
 while y!= NIL and x = right[y]
  do x<-y
  y<-p[y]
 return y

我知道“if right[x] != NIL then return tree-min”是什么意思,我已将其翻译为:

if(p->RChild) return fMinValue(p->RChild);//returns the min value of the sub-tree starting at the right child node of p

其余部分我无法理解。

if right[x] != NIL
 then return TREE-MINIMUM(right[x])

 y<-p[x]
 while y!= NIL and x = right[y]
  do x<-y
  y<-p[y]
 return y

I know what "if right[x] != NIL then return tree-min" means and I've translated it to:

if(p->RChild) return fMinValue(p->RChild);//returns the min value of the sub-tree starting at the right child node of p

The rest I'm having trouble understanding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早茶月光 2024-08-30 02:54:29

<- 最有可能是赋值运算符。 p 我猜是父母。你还有什么困惑?

<- is most likely the assignment operator. p I would guess is parent. What else are you confused about?

愁以何悠 2024-08-30 02:54:29

这里 p[] 几乎肯定意味着“的父节点”。您正在处理节点 x,因此 p[x] 表示“当前节点的父节点”(就像 right[x]表示“当前节点的右侧子节点”)。

<- 表示法是赋值。就像类 C 语言中的 = 一样。

这里介绍的算法的第二部分沿着树向上走,寻找您第一次登上左链接而不是右链接的时间。但我不确定是否会将其描述为后续功能。

Here p[] almost certainly means "the parent node of". You're working on node x, so p[x] means "the parent of the current node" (just like right[x] means "the right-hand child of the current node").

The <- notation is assignment. Like = in c-like languages.

The second part of the algorithm presented here walks up the tree looking for the first time you ascended a left link instead of a right one. But I'm not sure that I would describe this as a successor function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文