???
This commit is contained in:
parent
d54dd3eb6f
commit
bf0a0b3f40
26
bintree.c
26
bintree.c
@ -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);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user