This commit is contained in:
Tobias Busch 2025-12-02 18:57:39 +01:00
parent 514592c4fe
commit a13c7acf22
4 changed files with 26 additions and 18 deletions

View File

@ -8,11 +8,12 @@
* `treeSize`: zählt die Knoten im Baum (rekursiv),
* `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
// 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 = createNode(data);
}
// 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.

View File

@ -16,7 +16,17 @@
// creating random numbers.
unsigned int *createNumbers(unsigned int len)
{
//hier wird das array angelegt soll Einträge (zahlen) haben die zwichen 1 und 2* len liegen
// ran % 2*len
int *numbers[] = calloc(len, sizeof(int));
if(!numbers)
return NULL;
srand(time(NULL));
for(size_t i = 0; i < len; i++) {
numbers[i] = rand() % 2*len + 1;
}
}
// Returns only the only number in numbers which is present twice. Returns zero on errors.

19
stack.c
View File

@ -10,15 +10,14 @@
// Pushes data as pointer onto the stack.
StackNode* push(StackNode* stack, void* data) // es gibt bereits ein stack element, dieses wird übergeben + die daten, die in den stack müssen
{
if(!data)
return 0;
//if(!data)
//return 0; -> nicht notwendig
StackNode* newNode = calloc(1, sizeof(StackNode)); //Speicher reserviert für data und prev, jeweils nur zeiger
if (!newNode)
return 0;
return NULL;
newNode->prev = stack;
newNode->data = data;
return newNode;
@ -29,9 +28,10 @@ StackNode *push(StackNode *stack, void *data) // es gibt bereits ein stack eleme
StackNode* pop(StackNode* stack)
{
if(!stack)
return 0;
return NULL;
StackNode* prev = stack->prev;
free(stack);
return prev;
}
@ -39,7 +39,7 @@ StackNode *pop(StackNode *stack)
void* top(StackNode* stack)
{
if(!stack)
return 0;
return NULL;
return stack->data;
}
@ -49,9 +49,6 @@ void clearStack(StackNode *stack) //Annahme: erstes Element: prev = NULL;
if(!stack)
return;
StackNode *stack_tmp = stack;
while(stack_tmp) {
stack_tmp = pop(stack_tmp);
}
clearStack(stack->prev);
free(stack);
}

View File

@ -20,7 +20,7 @@ void test_pushFailsOnNullPointer(StackNode *stack, void *data) {
return;
}
void test_popFailsOnNullPointer() {
void test_popFailsOnNullPointer() { //pop on null returns NULL
StackNode* test = pop(NULL);
if (test == 0) {