02. 二叉树的遍历知识 #166
Replies: 2 comments
-
func (t *TreeNode[T]) levelOrder() {
var nodes = []*TreeNode[T]{t}
for len(nodes) != 0 {
var tmp = []*TreeNode[T]{}
for _, v := range nodes {
if v != nil {
tmp = append(tmp, v.left, v.right)
fmt.Println(v.data)
}
}
nodes = tmp
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
二叉树后序遍历的显式栈实现的第18行代码是多余的: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
02. 二叉树的遍历知识
二叉树的遍历知识 1. 二叉树的遍历简介 二叉树的遍历:指的是从根节点出发,按照某种次序依次访问二叉树中所有节点,使得每个节点被访问一次且仅被访问一次。 在二叉树的一些实际问题中,经常需要按照一定顺序对二叉树中每个节点逐个进行访问一次,用以查找具有某一特点的节点或者全部节点,然后对这些满足要求的节点进行处理。这里所说的「访问」就是指对该节点进行某种操作...
https://algo.itcharge.cn/07.Tree/01.Binary-Tree/02.Binary-Tree-Traverse/
Beta Was this translation helpful? Give feedback.
All reactions