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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
博客园 - 司徒正美
L
LangChain Blog
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
月光博客
月光博客
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
D
DataBreaches.Net

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
}