引自:https://blog.csdn.net/zhhp1001/article/details/88257018
测试代码:
int main(int argc, char* argv[]) {
BinaryTreeNode* A = new BinaryTreeNode(1);
BinaryTreeNode* B = new BinaryTreeNode(2);
BinaryTreeNode* C = new BinaryTreeNode(4);
BinaryTreeNode* D = new BinaryTreeNode(7);
BinaryTreeNode* E = new BinaryTreeNode(3);
BinaryTreeNode* F = new BinaryTreeNode(5);
BinaryTreeNode* G = new BinaryTreeNode(6);
BinaryTreeNode* H = new BinaryTreeNode(8);
A->leftchild = B;
A->rightchild = E;
B->leftchild = C;
C->rightchild = D;
E->leftchild = F;
E->rightchild = G;
G->leftchild = H;
std::cout << "Pre order traversal:" << std::endl;
pre_traversal(A);
std::cout << std::endl<< "In order traversal:" << std::endl;
in_traversal(A);
std::cout << std::endl << "Post order traversal:" << std::endl;
post_traversal(A);
return 0;
}