aufräumen
This commit is contained in:
parent
f8c297f84d
commit
a3b951d0a9
40
bintree.c
40
bintree.c
@ -2,11 +2,11 @@
|
|||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "bintree.h"
|
#include "bintree.h"
|
||||||
|
|
||||||
//TODO: binären Suchbaum implementieren
|
// TODO: binären Suchbaum implementieren
|
||||||
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv),
|
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv),
|
||||||
* `clearTree`: gibt den gesamten Baum frei (rekursiv),
|
* `clearTree`: gibt den gesamten Baum frei (rekursiv),
|
||||||
* `treeSize`: zählt die Knoten im Baum (rekursiv),
|
* `treeSize`: zählt die Knoten im Baum (rekursiv),
|
||||||
* `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. */
|
* `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. */
|
||||||
|
|
||||||
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
||||||
// 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).
|
||||||
@ -45,18 +45,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 counter = 0;
|
int counterL, counterR = 0;
|
||||||
|
if (root->left != NULL)
|
||||||
if(root != NULL)
|
|
||||||
{
|
{
|
||||||
treeSize(root->left);
|
counterL = treeSize(root->left) + 1;
|
||||||
counter++;
|
|
||||||
treeSize(root->right);
|
|
||||||
}
|
}
|
||||||
|
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];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user