bugfix bintree

This commit is contained in:
maxgrf 2025-12-11 11:47:05 +01:00
parent 75291daff4
commit 81fbacabdc
4 changed files with 9 additions and 7 deletions

View File

@ -80,31 +80,33 @@ void *nextTreeData(TreeNode *root)
if (stack) if (stack)
{ {
freeStack(stack); clearStack(&stack);
stack = NULL; stack = NULL;
} }
//leeren Stack initialisieren
stack = createStack(); stack = NULL;
// alle linken Knoten vom Wurzelknoten pushen // alle linken Knoten vom Wurzelknoten pushen
currentNode = root; currentNode = root;
while (currentNode) while (currentNode)
{ {
push(stack, currentNode); stack = push(stack, currentNode);
currentNode = currentNode->left; currentNode = currentNode->left;
} }
} }
// Stack ist leer, keine Daten mehr // Stack ist leer, keine Daten mehr
if (!stack || isEmpty(stack)) if (!stack)
return NULL; return NULL;
TreeNode *newNode = pop(stack); // nächster Knoten TreeNode *newNode = (TreeNode *)top(stack);
// Stack-Knoten entfernen
stack = pop(stack);
// Wenn rechter Teilbaum vorhanden → alle linken Knoten pushen // Wenn rechter Teilbaum vorhanden → alle linken Knoten pushen
currentNode = newNode->right; currentNode = newNode->right;
while (currentNode) while (currentNode)
{ {
push(stack, currentNode); stack = push(stack, currentNode);
currentNode = currentNode->left; currentNode = currentNode->left;
} }
return newNode->data; // Daten zurückgeben return newNode->data; // Daten zurückgeben

BIN
main.o Normal file

Binary file not shown.

BIN
numbers.o

Binary file not shown.

BIN
stack.o Normal file

Binary file not shown.