二叉树的三种遍历方式(递归)先根中根后根
二叉树的三种遍历方式(递归)
先根
1void preOrder(BinTree tree){ 2 if(tree == NULL){ 3 return ; 4 } 5 visit(tree); 6 preOrder(tree->leftNode); 7 preOrder(tree->rightNode); 8}
中根
1void inOrder(BinTree tree){ 2 if(tree == NULL){ 3 return ; 4 } 5 inOrder(tree->leftNode); 6 visit(tree); 7 inOrder(tree->rightNode); 8}
后根
1void postOrder(BinTree tree){ 2 if(tree == NULL){ 3 return ; 4 } 5 postOrder(tree->leftNode); 6 postOrder(tree->rightNode); 7 visit(tree); 8}