二叉树遍历

引自: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;
}

posted @ 2020-06-21 20:41  19l92y11p26  阅读(92)  评论(0编辑  收藏  举报
/*鼠标跟随效果*/ /* 点击爆炸效果*/
/*鼠标跟随效果*/
Live2D