aufräumen
This commit is contained in:
parent
f8c297f84d
commit
a3b951d0a9
30
bintree.c
30
bintree.c
@ -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];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user