这个伪代码是什么意思? - 二叉搜索树后继函数
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
<-
最有可能是赋值运算符。p
我猜是父母。你还有什么困惑?<-
is most likely the assignment operator.p
I would guess is parent. What else are you confused about?这里
p[]
几乎肯定意味着“的父节点”。您正在处理节点x
,因此p[x]
表示“当前节点的父节点”(就像right[x]
表示“当前节点的右侧子节点”)。<-
表示法是赋值。就像类 C 语言中的=
一样。这里介绍的算法的第二部分沿着树向上走,寻找您第一次登上左链接而不是右链接的时间。但我不确定是否会将其描述为后续功能。
Here
p[]
almost certainly means "the parent node of". You're working on nodex
, sop[x]
means "the parent of the current node" (just likeright[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.