NextTreeData erster versuch

This commit is contained in:
silvana884 2025-12-03 22:07:13 +01:00
parent 7a20acd8f6
commit be5c1754f9
3 changed files with 29 additions and 4 deletions

View File

@ -66,12 +66,36 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
// push the top node and push all its left nodes.
void *nextTreeData(TreeNode *root)
{
if(root == NULL)
static StackNode *stack = NULL;
// Beim ersten Aufruf: ganzen linken Pfad pushen
if(root != NULL)
{
while(root != NULL)
{
stack = push(stack, root); // TreeNode auf den Stack
root = root->left;
}
}
stackNode.top(root);
// Wenn Stack leer -> fertig
if(stack == NULL)
return NULL;
// Obersten Knoten holen
TreeNode *node = (TreeNode*) top(stack);
stack = pop(stack);
// Rechten Teilbaum absteigen
TreeNode *right = node->right;
while(right != NULL)
{
stack = push(stack, right);
right = right->left;
}
return node->data;
}
// Releases all memory resources (including data copies).

Binary file not shown.

View File

@ -1,2 +1,3 @@
Silvana;9944
hannes;9910
player1;3999