Compare commits

..

1 Commits
main ... jakob

Author SHA1 Message Date
e0b80e8068 add to tree wip 2025-12-11 11:19:02 +01:00

View File

@ -12,7 +12,39 @@
// if isDuplicate is NULL, otherwise ignores duplicates and sets isDuplicate to 1 (or to 0 if a new entry is added). // 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 *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
{ {
if (root = NULL)
{
TreeNode *node = malloc(sizeof(data));
strcpy(root, data);
node->left = NULL;
node->right = NULL;
if (isDuplicate != NULL)
{
isDuplicate = 0;
}
}
return node;
int compare = compareFct(data, root->data);
if (compare < 0) // linker Teilbaum
{
root->left = addToTree();
}
else if (compare > 0) // rechter Teilbaum
{
root->right = addToTree();
}
else
{
if (isDuplicate != NULL)
{
isDuplicate = 1;
}
return root;
}
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. // 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.
@ -20,17 +52,14 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
// push the top node and push all its left nodes. // push the top node and push all its left nodes.
void *nextTreeData(TreeNode *root) 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)
{ {
} }
// 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)
{ {
} }