今天收获了什么呢?
关于 c++ 的 vector 类型:其实就是动态的数组罢了,push_back(添加数据),还有关于后续遍历的迭代方式。
大致的模版如下 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function postOrder(root) {
let pre = null;
let stack = [];
let res = [];
while (root || stack.length > 0) {
while (root) {
stack.push(root);
root = root.left;
}

const node = stack.pop();

if (node.right == null || node.right !== pre) {
res.push(root.val);
pre = root;
root = null;
} else {
stack.push(node);
root = root.right;
}
}
}

其二,关于前序的莫里斯遍历,也是比较难。。提前阻断,层序遍历,路径求和(层序遍历的方式也可以)


http://example.com/2023/07/13/思考记录/日记/21-12-11/
作者
chen heng cheng
发布于
2023年7月13日
许可协议