Java中二叉树存储结构实现(5)

ThreeLinkBinTree<String> binTree = new ThreeLinkBinTree<String>("根节点");
        // 依次添加节点
        ThreeLinkBinTree.TreeNode tn1 = binTree.addNode(binTree.root(), "第二层左节点", true);
        ThreeLinkBinTree.TreeNode tn2 = binTree.addNode(binTree.root(), "第二层右节点", false);
        ThreeLinkBinTree.TreeNode tn3 = binTree.addNode(tn2, "第三层左节点", true);
        ThreeLinkBinTree.TreeNode tn4 = binTree.addNode(tn2, "第三层右节点", false);
        ThreeLinkBinTree.TreeNode tn5 = binTree.addNode(tn3, "第四层左节点", true);

System.out.println("tn2的左子节点:" + binTree.leftChild(tn2));
        System.out.println("tn2的右子节点:" + binTree.rightChild(tn2));
        System.out.println(binTree.deep());

}

}

程序输出:

tn2的左子节点:第三层左节点
tn2的右子节点:第三层右节点
4

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/3fc7024f85b24f67a9e1110c2dde84e4.html