二叉树-前序遍历
2023-12-06 11:13:56 0 举报
二叉树-前序遍历
作者其他创作
大纲/内容
71
right
stack
current
left
16
25
73
3. current = current.left
87
33
res
51
1
pointer(71)
pointer(73)
pointer(51)
36
1. res.push(current.value)
2. current = current?.right ?? null
pointer(36)
80
2. stack.push(current)
1. current = stack.pop()
pointer(33)
pointer(16)
1. current = stack.pop()
指针
数组
2. current = current?.right ?? null
null
需要断开的链接
3. current = current.left
根据红色虚线链接可得二叉树
pointer(1)
i
1. current = stack.pop()
右子节点索引 rightIdx = 2 * i + 2
左子节点索引 leftIdx = 2 * i + 1
pointer(80)
0
2
3
4
5
6
7
8
9
pointer(87)
新建立的链接
pointer(25)
0 条评论
回复 删除
下一页