Compare commits
2
Commits
5b576589e3
...
temp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3b951d0a9 | ||
|
|
f8c297f84d |
@@ -6,3 +6,6 @@ runNumbersTest.exe
|
||||
numbers.o
|
||||
.vscode/launch.json
|
||||
.vscode/settings.json
|
||||
*.o
|
||||
*.exe
|
||||
runBintreeTest
|
||||
|
||||
@@ -45,18 +45,36 @@ void *nextTreeData(TreeNode *root)
|
||||
// Releases all memory resources (including data copies).
|
||||
void clearTree(TreeNode *root)
|
||||
{
|
||||
if (root == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (root->left != NULL)
|
||||
{
|
||||
clearTree(root->left);
|
||||
free(root->left);
|
||||
}
|
||||
else if (root->right != NULL)
|
||||
{
|
||||
clearTree(root->right);
|
||||
free(root->right);
|
||||
}
|
||||
root->data = NULL;
|
||||
}
|
||||
|
||||
// Returns the number of entries in the tree given by root.
|
||||
unsigned int treeSize(const TreeNode *root)
|
||||
{
|
||||
int counter = 0;
|
||||
|
||||
if(root != NULL)
|
||||
int counterL, counterR = 0;
|
||||
if (root->left != NULL)
|
||||
{
|
||||
treeSize(root->left);
|
||||
counter++;
|
||||
treeSize(root->right);
|
||||
counterL = treeSize(root->left) + 1;
|
||||
}
|
||||
else if (root->right != NULL)
|
||||
{
|
||||
counterR = treeSize(root->right) + 1;
|
||||
}
|
||||
|
||||
return counterL + counterR;
|
||||
}
|
||||
@@ -136,6 +136,11 @@ unsigned int getDuplicate(const unsigned int numbers[], unsigned int len)
|
||||
unsigned int temp[len];
|
||||
unsigned int duplicate = 0;
|
||||
|
||||
/*if(numbers == NULL || (sizeof(numbers) / sizeof(typeof(numbers)) != len))
|
||||
{
|
||||
return 0;S
|
||||
}*/
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
temp[i] = numbers[i];
|
||||
|
||||
+6
-2
@@ -4,7 +4,7 @@
|
||||
#include "unity.h"
|
||||
|
||||
|
||||
void sizeTest()
|
||||
void treeTest()
|
||||
{
|
||||
TreeNode root;
|
||||
TreeNode node1;
|
||||
@@ -32,6 +32,10 @@ void sizeTest()
|
||||
TEST_ASSERT_EQUAL_INT(3,treeSize(&root));
|
||||
|
||||
|
||||
clearTree(&root);
|
||||
TEST_ASSERT_EQUAL_INT(0,treeSize(&root));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
@@ -50,7 +54,7 @@ int main()
|
||||
|
||||
printf("============================\nNumbers tests\n============================\n");
|
||||
|
||||
RUN_TEST(sizeTest);
|
||||
RUN_TEST(treeTest);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user