前序遍历
A->C->D->E->F->H->G->B
void traversal(Node *node) {
if (!node->left && node->right) {res.push_back(node); return;)
if (node->left) traversal(node->left);
if (node->right) traversal(node->right);
}
中序遍历
D->E->C->A->H->F->B->G
void traversal(Node *node) {
if (node->left) traversal(node->left);
if (!node->left && node->right) {res.push_back(node); return;)
if (node->right) traversal(node->right);
}
后序遍历
E->D->C->->H->B->G->F->A
void traversal(Node *node) {
if (node->left) traversal(node->left);
if (node->right) traversal(node->right);
if (!node->left && node->right) {res.push_back(node); return;)
}
标签:node,Node,遍历,traversal,right,二叉树,left
From: https://www.cnblogs.com/comein/p/16732230.html