diff --git a/bintree.c b/bintree.c index ece271f..82791ee 100644 --- a/bintree.c +++ b/bintree.c @@ -68,8 +68,29 @@ 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) { + 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; + +} // Releases all memory resources (including data copies). void clearTree(TreeNode *root)