generated from freudenreichan/info2Praktikum-DobleSpiel
Added nextTreeData and iterateThroughTree in bintree.c
This commit is contained in:
parent
00df653018
commit
b857e6b273
17
bintree.c
17
bintree.c
@ -49,7 +49,24 @@ 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)
|
||||||
{
|
{
|
||||||
|
StackNode *stackRoot = NULL;//Generates a new, empty stack
|
||||||
|
stackRoot = iterateThroughTree(root, stackRoot); //Fills the stack via the helping function iterateThroughTree
|
||||||
|
stackNode * tempBuffer = pop(stackRoot);
|
||||||
|
clearStack(stackRoot);
|
||||||
|
return tempBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Function to aid nextTreeData
|
||||||
|
StackNode *iterateThroughTree(TreeNode *root, StackNode *stackRoot)
|
||||||
|
{
|
||||||
|
if(!root)
|
||||||
|
{
|
||||||
|
return stackRoot;
|
||||||
|
}
|
||||||
|
stackRoot = iterateThroughTree(root->left, stackRoot);
|
||||||
|
stackNode = push(stackNode, root->data);
|
||||||
|
stackRoot = iterateThroughTree(root->right, stackRoot);
|
||||||
|
return stackRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Releases all memory resources (including data copies).
|
// Releases all memory resources (including data copies).
|
||||||
|
|||||||
@ -23,5 +23,6 @@ void *nextTreeData(TreeNode *root);
|
|||||||
void clearTree(TreeNode *root);
|
void clearTree(TreeNode *root);
|
||||||
// Returns the number of entries in the tree given by root.
|
// Returns the number of entries in the tree given by root.
|
||||||
unsigned int treeSize(const TreeNode *root);
|
unsigned int treeSize(const TreeNode *root);
|
||||||
|
//Function to aid nextTreeData
|
||||||
|
StackNode iterateThroughTree(TreeNode *root, StackNode stackRoot);
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user