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