本文整理汇总了C++中ConnectTreeNodes函数的典型用法代码示例。如果您正苦于以下问题:C++ ConnectTreeNodes函数的具体用法?C++ ConnectTreeNodes怎么用?C++ ConnectTreeNodes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ConnectTreeNodes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestA
// 8
// 6 10
// 5 7 9 11
void TestA()
{
BinaryTreeNode* pNode8 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6);
BinaryTreeNode* pNode10 = CreateBinaryTreeNode(10);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);
BinaryTreeNode* pNode9 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNode11 = CreateBinaryTreeNode(11);
ConnectTreeNodes(pNode8, pNode6, pNode10);
ConnectTreeNodes(pNode6, pNode5, pNode7);
ConnectTreeNodes(pNode10, pNode9, pNode11);
Test("TestA0", pNode8, 0, true, -1);
Test("TestA1", pNode8, 1, false, 5);
Test("TestA2", pNode8, 2, false, 6);
Test("TestA3", pNode8, 3, false, 7);
Test("TestA4", pNode8, 4, false, 8);
Test("TestA5", pNode8, 5, false, 9);
Test("TestA6", pNode8, 6, false, 10);
Test("TestA7", pNode8, 7, false, 11);
Test("TestA8", pNode8, 8, true, -1);
DestroyTree(pNode8);
printf("\n\n");
}
示例2: Test2
// 测试二叉树:出叶子结点之外,左右的结点都有且只有一个左子结点
// 8
// 7
// 6
// 5
// 4
void Test2()
{
printf("=====Test2 starts:=====\n");
BinaryTreeNode* pNode8 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);
BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
ConnectTreeNodes(pNode8, pNode7, NULL);
ConnectTreeNodes(pNode7, pNode6, NULL);
ConnectTreeNodes(pNode6, pNode5, NULL);
ConnectTreeNodes(pNode5, pNode4, NULL);
PrintTree(pNode8);
printf("=====Test2: MirrorRecursively=====\n");
MirrorRecursively(pNode8);
PrintTree(pNode8);
printf("=====Test2: MirrorIteratively=====\n");
MirrorIteratively(pNode8);
PrintTree(pNode8);
DestroyTree(pNode8);
}
示例3: TestB
// 5
// /
// 4
// /
// 3
// /
// 2
// /
// 1
void TestB()
{
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNode3 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNode2 = CreateBinaryTreeNode(2);
BinaryTreeNode* pNode1 = CreateBinaryTreeNode(1);
ConnectTreeNodes(pNode5, pNode4, nullptr);
ConnectTreeNodes(pNode4, pNode3, nullptr);
ConnectTreeNodes(pNode3, pNode2, nullptr);
ConnectTreeNodes(pNode2, pNode1, nullptr);
Test("TestB0", pNode5, 0, true, -1);
Test("TestB1", pNode5, 1, false, 1);
Test("TestB2", pNode5, 2, false, 2);
Test("TestB3", pNode5, 3, false, 3);
Test("TestB4", pNode5, 4, false, 4);
Test("TestB5", pNode5, 5, false, 5);
Test("TestB6", pNode5, 6, true, -1);
DestroyTree(pNode5);
printf("\n\n");
}
示例4: Test1
// ====================测试代码====================
// 测试完全二叉树:除了叶子节点,其他节点都有两个子节点
// 8
// 6 10
// 5 7 9 11
void Test1()
{
printf("=====Test1 starts:=====\n");
BinaryTreeNode* pNode8 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6);
BinaryTreeNode* pNode10 = CreateBinaryTreeNode(10);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);
BinaryTreeNode* pNode9 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNode11 = CreateBinaryTreeNode(11);
ConnectTreeNodes(pNode8, pNode6, pNode10);
ConnectTreeNodes(pNode6, pNode5, pNode7);
ConnectTreeNodes(pNode10, pNode9, pNode11);
PrintTree(pNode8);
printf("=====Test1: MirrorRecursively=====\n");
MirrorRecursively(pNode8);
PrintTree(pNode8);
printf("=====Test1: MirrorIteratively=====\n");
MirrorIteratively(pNode8);
PrintTree(pNode8);
DestroyTree(pNode8);
}
示例5: Test2
// There are branches in trees, and tree B is not a subtree of tree A
// 8 8
// / \ / \
// 8 7 9 2
// / \
// 9 3
// / \
// 4 7
void Test2()
{
BinaryTreeNode* pNodeA1 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeA2 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeA3 = CreateBinaryTreeNode(7);
BinaryTreeNode* pNodeA4 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNodeA5 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNodeA6 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNodeA7 = CreateBinaryTreeNode(7);
ConnectTreeNodes(pNodeA1, pNodeA2, pNodeA3);
ConnectTreeNodes(pNodeA2, pNodeA4, pNodeA5);
ConnectTreeNodes(pNodeA5, pNodeA6, pNodeA7);
BinaryTreeNode* pNodeB1 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeB2 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNodeB3 = CreateBinaryTreeNode(2);
ConnectTreeNodes(pNodeB1, pNodeB2, pNodeB3);
Test("Test2", pNodeA1, pNodeB1, false);
DestroyTree(pNodeA1);
DestroyTree(pNodeB1);
}
示例6: Test1
// ====================测试代码====================
// 8
// 6 10
// 5 7 9 11
void Test1()
{
BinaryTreeNode* pNode8 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6);
BinaryTreeNode* pNode10 = CreateBinaryTreeNode(10);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);
BinaryTreeNode* pNode9 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNode11 = CreateBinaryTreeNode(11);
ConnectTreeNodes(pNode8, pNode6, pNode10);
ConnectTreeNodes(pNode6, pNode5, pNode7);
ConnectTreeNodes(pNode10, pNode9, pNode11);
printf("====Test1 Begins: ====\n");
printf("Expected Result is:\n");
printf("8 \n");
printf("10 6 \n");
printf("5 7 9 11 \n\n");
printf("Actual Result is: \n");
Print(pNode8);
printf("\n");
DestroyTree(pNode8);
}
示例7: TestC
// 1
// \
// 2
// \
// 3
// \
// 4
// \
// 5
void TestC()
{
BinaryTreeNode* pNode1 = CreateBinaryTreeNode(1);
BinaryTreeNode* pNode2 = CreateBinaryTreeNode(2);
BinaryTreeNode* pNode3 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
ConnectTreeNodes(pNode1, nullptr, pNode2);
ConnectTreeNodes(pNode2, nullptr, pNode3);
ConnectTreeNodes(pNode3, nullptr, pNode4);
ConnectTreeNodes(pNode4, nullptr, pNode5);
Test("TestC0", pNode1, 0, true, -1);
Test("TestC1", pNode1, 1, false, 1);
Test("TestC2", pNode1, 2, false, 2);
Test("TestC3", pNode1, 3, false, 3);
Test("TestC4", pNode1, 4, false, 4);
Test("TestC5", pNode1, 5, false, 5);
Test("TestC6", pNode1, 6, true, -1);
DestroyTree(pNode1);
printf("\n\n");
}
示例8: main
int main() {
BinaryTreeNode* pNodeA1 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeA2 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeA3 = CreateBinaryTreeNode(7);
BinaryTreeNode* pNodeA4 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNodeA5 = CreateBinaryTreeNode(2);
BinaryTreeNode* pNodeA6 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNodeA7 = CreateBinaryTreeNode(7);
ConnectTreeNodes(pNodeA1, pNodeA2, pNodeA3);
ConnectTreeNodes(pNodeA2, pNodeA4, pNodeA5);
ConnectTreeNodes(pNodeA5, pNodeA6, pNodeA7);
BinaryTreeNode* pNodeB1 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeB2 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNodeB3 = CreateBinaryTreeNode(2);
ConnectTreeNodes(pNodeB1, pNodeB2, pNodeB3);
printf("%d\n",HasSubtreeCore(pNodeA1, pNodeB1));
return 0;
}
示例9: Test_32_2_6
// 100
// /
// 50
// \
// 150
void Test_32_2_6()
{
BinaryTreeNode* pNode100 = CreateBinaryTreeNode(100);
BinaryTreeNode* pNode50 = CreateBinaryTreeNode(50);
BinaryTreeNode* pNode150 = CreateBinaryTreeNode(150);
ConnectTreeNodes(pNode100, pNode50, nullptr);
ConnectTreeNodes(pNode50, nullptr, pNode150);
Test_32_2("Test_32_2_6", pNode100);
DestroyTree(pNode100);
}
示例10: Test7
// Tree A is empty
void Test7()
{
BinaryTreeNode* pNodeB1 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeB2 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNodeB3 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNodeB4 = CreateBinaryTreeNode(2);
ConnectTreeNodes(pNodeB1, NULL, pNodeB2);
ConnectTreeNodes(pNodeB2, pNodeB3, pNodeB4);
Test("Test7", NULL, pNodeB1, false);
DestroyTree(pNodeB1);
}
示例11: Test8
// Tree B is empty
void Test8()
{
BinaryTreeNode* pNodeA1 = CreateBinaryTreeNode(8);
BinaryTreeNode* pNodeA2 = CreateBinaryTreeNode(9);
BinaryTreeNode* pNodeA3 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNodeA4 = CreateBinaryTreeNode(2);
ConnectTreeNodes(pNodeA1, NULL, pNodeA2);
ConnectTreeNodes(pNodeA2, pNodeA3, pNodeA4);
Test("Test8", pNodeA1, NULL, false);
DestroyTree(pNodeA1);
}
示例12: Test_32_2_2
// 5
// 4
// 3
// 2
void Test_32_2_2()
{
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNode3 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNode2 = CreateBinaryTreeNode(2);
ConnectTreeNodes(pNode5, pNode4, nullptr);
ConnectTreeNodes(pNode4, pNode3, nullptr);
ConnectTreeNodes(pNode3, pNode2, nullptr);
Test_32_2("Test_32_2_2", pNode5);
DestroyTree(pNode5);
}
示例13: Test2
// 10
// / \
// 5 12
// /\
// 4 7
// 没有路径上的结点和为15
void Test2()
{
BinaryTreeNode* pNode10 = CreateBinaryTreeNode(10);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode12 = CreateBinaryTreeNode(12);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);
ConnectTreeNodes(pNode10, pNode5, pNode12);
ConnectTreeNodes(pNode5, pNode4, pNode7);
printf("No paths should be found in Test2.\n");
Test("Test2", pNode10, 15);
DestroyTree(pNode10);
}
示例14: Test2
// 11
// 6 16
// 5 7 9
void Test2()
{
BinaryTreeNode* pNode11 = CreateBinaryTreeNode(11);
BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6);
BinaryTreeNode* pNode16 = CreateBinaryTreeNode(16);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);
BinaryTreeNode* pNode9 = CreateBinaryTreeNode(9);
ConnectTreeNodes(pNode11, pNode6, pNode16);
ConnectTreeNodes(pNode6, pNode5, pNode7);
ConnectTreeNodes(pNode16, NULL, pNode9);
Test("Test2", pNode11, 3);
DestroyTree(pNode11);
}
示例15: Test5
// 1
// \
// 2
// \
// 3
// \
// 4
// \
// 5
void Test5()
{
BinaryTreeNode* pNode1 = CreateBinaryTreeNode(1);
BinaryTreeNode* pNode2 = CreateBinaryTreeNode(2);
BinaryTreeNode* pNode3 = CreateBinaryTreeNode(3);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
ConnectTreeNodes(pNode1, NULL, pNode2);
ConnectTreeNodes(pNode2, NULL, pNode3);
ConnectTreeNodes(pNode3, NULL, pNode4);
ConnectTreeNodes(pNode4, NULL, pNode5);
Test("Test5", pNode1, false);
DestroyTree(pNode1);
}