This commit is contained in:
Nick Haller 2025-12-02 13:51:42 +01:00
parent d54dd3eb6f
commit bf0a0b3f40
3 changed files with 26 additions and 0 deletions

View File

@ -12,7 +12,26 @@
// if isDuplicate is NULL, otherwise ignores duplicates and sets isDuplicate to 1 (or to 0 if a new entry is added).
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
{
TreeNode newNode = {data, NULL, NULL};
if(root == NULL)
{
return &newNode;
}
if (data < root->data)
{
root->left = addToTree(root->left, data, dataSize,compareFct, isDuplicate);
}
else if(data > root->data)
{
root->right = addToTree(root->right, data, dataSize,compareFct, isDuplicate);
}
return root;
}
// 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.
@ -32,5 +51,12 @@ void clearTree(TreeNode *root)
// Returns the number of entries in the tree given by root.
unsigned int treeSize(const TreeNode *root)
{
int counter = 0;
if(root != NULL)
{
treeSize(root->left);
counter++;
treeSize(root->right);
}
}

BIN
numbers.o

Binary file not shown.

Binary file not shown.