Implement nextTreeData()
This commit is contained in:
parent
a89ed94c97
commit
97a11d8ac6
23
bintree.c
23
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user