Compare commits
1 Commits
simons_weg
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
804294b96e |
28
bintree.c
28
bintree.c
@ -13,6 +13,7 @@
|
|||||||
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
|
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterates over the tree given by root. Follows the usage of strtok. If tree is NULL, the next entry of the last tree given is returned in ordering direction.
|
// Iterates over the tree given by root. Follows the usage of strtok. If tree is NULL, the next entry of the last tree given is returned in ordering direction.
|
||||||
@ -26,11 +27,36 @@ void *nextTreeData(TreeNode *root)
|
|||||||
// Releases all memory resources (including data copies).
|
// Releases all memory resources (including data copies).
|
||||||
void clearTree(TreeNode *root)
|
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.
|
// Returns the number of entries in the tree given by root.
|
||||||
unsigned int treeSize(const TreeNode *root)
|
unsigned int treeSize(const TreeNode *root)
|
||||||
{
|
{
|
||||||
|
int counterL, counterR = 0;
|
||||||
|
if (root->left != NULL)
|
||||||
|
{
|
||||||
|
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 temp[len];
|
||||||
unsigned int duplicate = 0;
|
unsigned int duplicate = 0;
|
||||||
|
|
||||||
|
/*if(numbers == NULL || (sizeof(numbers) / sizeof(typeof(numbers)) != len))
|
||||||
|
{
|
||||||
|
return 0;S
|
||||||
|
}*/
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
temp[i] = numbers[i];
|
temp[i] = numbers[i];
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user