惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
S
SegmentFault 最新的问题
量子位
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
博客园 - Franky
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
B
Blog RSS Feed
C
Check Point Blog
The Cloudflare Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
V
Visual Studio Blog
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

vzard's blog

跳表 - vzard's blog redis的事务 - vzard's blog redis数据类型及使用场景 - vzard's blog 二叉树非递归遍历统一写法 - vzard's blog 灵魂七问 - vzard's blog XPath线索追踪技术 - vzard's blog cron表达式小记 - vzard's blog 计算广告核心问题总结 - vzard's blog 实现一个简单的http服务器 - vzard's blog 由三次握手想到的... - vzard's blog Js原型链解读 - vzard's blog 统计知识(1) - vzard's blog 同步Github上的fork - vzard's blog Http协议杂谈 - vzard's blog JAVA虚拟机的类加载机制 - vzard's blog HashMap源码剖析 - vzard's blog Java中的锁 - vzard's blog 关于volatile - vzard's blog 修复hexo博客的一个bug - vzard's blog
二叉搜索树的一些性质 - vzard's blog
vzardlloo · 2020-09-22 · via vzard's blog

二叉搜索树的中序遍历的结果序列是一个递增排序的序列。

中序遍历的顺序是:左节点 - 根节点 - 右节点

示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
result := make([]*Node,0)
func inorder(root *Node) {
if root == nil {
return
}

inorder(root.Left)
result = append(result,root)
inorder(root.Right)

return
}

二叉搜索树的后继节点

即比当前节点大的最小节点,主要思路:取改节点的右节点,然后一直取左节点直到左节点为空,最后指向的就是该节点的后继节点

示例代码:

1
2
3
4
5
6
7
func Successor(node *Node) *Node {
succ := node.Right
for succ.Left != nil {
succ = node.Left
}
return succ
}

二叉搜索树的前驱节点

即比当前节点小的最大节点,主要思路:取改节点的左节点,然后一直取右节点直到右节点为空,最后指向的就是该节点的前驱节点

示例代码:

1
2
3
4
5
6
7
func Predecessor(node *Node) *Node {
pre := node.Left
for pre.Right != nil {
pre = pre.Right
}
return pre
}