// 不是完全二叉树,但是平衡二叉树
// 1
// / \
// 2 3
// /\ \
// 4 5 6
// /
// 7
int main()
{
BinaryTreeNode* pNode1 = CreateBinaryTreeNode(1);
BinaryTreeNode* pNode2 = CreateBinaryTreeNode(2);
BinaryTreeNode* pNode3 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);
ConnectTreeNodes(pNode1, pNode2, pNode3);
ConnectTreeNodes(pNode2, pNode4, pNode5);
ConnectTreeNodes(pNode3, pNode6, pNode7);
printf("Solution1 begins: ");
if(IsBalanced_Solution1(pNode1))
printf("is balanced.\n");
else
printf("not balanced.\n");
printf("Solution2 begins: ");
if(IsBalanced_Solution2(pNode1))
printf("is balanced.\n");
else
printf("not balanced.\n");
printf("\n");
DestroyTree(pNode1);
return 0;
}
在Java中实现的二叉树结构