Implement nextTreeData()

This commit is contained in:
D2A62006 2025-12-07 20:17:04 +01:00
parent a89ed94c97
commit 97a11d8ac6

View File

@ -68,6 +68,27 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
// push the top node and push all its left nodes. // push the top node and push all its left nodes.
void *nextTreeData(TreeNode *root) void *nextTreeData(TreeNode *root)
{ {
static StackNode *stack = NULL;
static TreeNode *current = NULL;
if(root != NULL){
clearStack(stack);
stack = NULL;
current = root;
}
while (current != NULL)
{
stack = push(stack, current);
current = current->left;
}
TreeNode *node = (TreeNode *)top(stack);
stack = pop(stack);
current = node->right;
return node->data;
} }