Skip to content

Commit

Permalink
add a test case for symmetrical binary trees
Browse files Browse the repository at this point in the history
  • Loading branch information
zhedahht committed May 20, 2014
1 parent 84a22da commit 64c9da2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions SymmetricalBinaryTree/SymmetricalBinaryTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,68 @@ void Test8()
Test("Test8", NULL, true);
}

// All nodes have the same value
// 5
// / \
// 5 5
// / \
// 5 5
// / \
// 5 5
void Test9()
{
BinaryTreeNode* pNode1 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode21 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode22 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode31 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode32 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode41 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode42 = CreateBinaryTreeNode(5);

ConnectTreeNodes(pNode1, pNode21, pNode22);
ConnectTreeNodes(pNode21, pNode31, NULL);
ConnectTreeNodes(pNode22, NULL, pNode32);
ConnectTreeNodes(pNode31, pNode41, NULL);
ConnectTreeNodes(pNode32, NULL, pNode42);
ConnectTreeNodes(pNode41, NULL, NULL);
ConnectTreeNodes(pNode42, NULL, NULL);

Test("Test9", pNode1, true);

DestroyTree(pNode1);
}

// All nodes have the same value
// 5
// / \
// 5 5
// / \
// 5 5
// / /
// 5 5
void Test10()
{
BinaryTreeNode* pNode1 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode21 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode22 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode31 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode32 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode41 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode42 = CreateBinaryTreeNode(5);

ConnectTreeNodes(pNode1, pNode21, pNode22);
ConnectTreeNodes(pNode21, pNode31, NULL);
ConnectTreeNodes(pNode22, NULL, pNode32);
ConnectTreeNodes(pNode31, pNode41, NULL);
ConnectTreeNodes(pNode32, pNode42, NULL);
ConnectTreeNodes(pNode41, NULL, NULL);
ConnectTreeNodes(pNode42, NULL, NULL);

Test("Test10", pNode1, false);

DestroyTree(pNode1);
}

void main(int argc, char* argv[])
{
Test1();
Expand All @@ -233,4 +295,6 @@ void main(int argc, char* argv[])
Test6();
Test7();
Test8();
Test9();
Test10();
}

0 comments on commit 64c9da2

Please sign in to comment.