class Node{
char val;
Node left;
Node right;
public Node(char val) {
this.val = val;
}
@Override
public String toString() {
return "Node{" +
"val=" + val +
'}';
}
}
public class BinaryTree {
private static Node root = null;
public static Node build(){
Node A = new Node('A');
Node B = new Node('B');
Node C = new Node('C');
Node D = new Node('D');
Node E = new Node('E');
Node F = new Node('F');
Node G = new Node('G');
A.left = B;
A.right = C;
B.left = D;
B.right = E;
E.left = G;
C.right = F;
return A;
}
//先序遍历
public static void prevOrder(Node root){
if(root == null){
return;
二叉树的先序, 中序, 后序遍历, 求二叉树节点个数, 求二叉树叶子节点个数.
最新推荐文章于 2024-04-10 19:10:29 发布
这篇博客详细讲解了二叉树的先序、中序、后序遍历算法,并提供了求解二叉树节点总数和叶子节点数量的方法。
摘要由CSDN通过智能技术生成