treeSize and treeSize test now workingW
This commit is contained in:
parent
21aa67b165
commit
9ee0f9e281
16
bintree.c
16
bintree.c
@ -24,7 +24,7 @@
|
||||
TreeNode *addToTreeRec (TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate, const int root);
|
||||
void clearTreeRec (TreeNode *currentNode);
|
||||
void clearNode (TreeNode *node);
|
||||
void treeSizeRec (const TreeNode *currentNode, unsigned int *nodeCount);
|
||||
int treeSizeRec (const TreeNode *currentNode);
|
||||
|
||||
|
||||
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
||||
@ -134,19 +134,23 @@ unsigned int treeSize(const TreeNode *root)
|
||||
unsigned int amountOfNodes = 0;
|
||||
|
||||
|
||||
treeSizeRec(root, &amountOfNodes);
|
||||
amountOfNodes = treeSizeRec(root);
|
||||
|
||||
|
||||
return amountOfNodes;
|
||||
}
|
||||
|
||||
void treeSizeRec(const TreeNode *currentNode, unsigned int *nodeCount)
|
||||
|
||||
int treeSizeRec(const TreeNode *currentNode)
|
||||
{
|
||||
int nodeCount = 0;
|
||||
|
||||
|
||||
if (currentNode != NULL)
|
||||
{
|
||||
treeSizeRec(currentNode->left, nodeCount);
|
||||
*nodeCount++;
|
||||
treeSizeRec(currentNode->right, nodeCount);
|
||||
nodeCount += treeSizeRec(currentNode->left);
|
||||
nodeCount += treeSizeRec(currentNode->right);
|
||||
return nodeCount + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -163,7 +163,6 @@ void test_treeSizeWorkingLikeExpected(void)
|
||||
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
|
||||
testTreeSize = treeSize(testRoot);
|
||||
|
||||
@ -182,7 +181,7 @@ int main()
|
||||
RUN_TEST(test_addToTreeExpandsTreeCorrectly);
|
||||
// RUN_TEST(test_nextTreeDataReturnsNextDataCorrectly);
|
||||
RUN_TEST(test_clearTreeworksLikeExpected);
|
||||
// RUN_TEST(test_treeSizeWorkingLikeExpected);
|
||||
RUN_TEST(test_treeSizeWorkingLikeExpected);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user