generated from freudenreichan/info2Praktikum-DobleSpiel
NextTreeData erster versuch
This commit is contained in:
parent
7a20acd8f6
commit
be5c1754f9
32
bintree.c
32
bintree.c
@ -66,12 +66,36 @@ 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)
|
||||
{
|
||||
if(root == NULL)
|
||||
static StackNode *stack = NULL;
|
||||
|
||||
// Beim ersten Aufruf: ganzen linken Pfad pushen
|
||||
if(root != NULL)
|
||||
{
|
||||
|
||||
|
||||
while(root != NULL)
|
||||
{
|
||||
stack = push(stack, root); // TreeNode auf den Stack
|
||||
root = root->left;
|
||||
}
|
||||
}
|
||||
stackNode.top(root);
|
||||
|
||||
// Wenn Stack leer -> fertig
|
||||
if(stack == NULL)
|
||||
return NULL;
|
||||
|
||||
// Obersten Knoten holen
|
||||
TreeNode *node = (TreeNode*) top(stack);
|
||||
stack = pop(stack);
|
||||
|
||||
// Rechten Teilbaum absteigen
|
||||
TreeNode *right = node->right;
|
||||
while(right != NULL)
|
||||
{
|
||||
stack = push(stack, right);
|
||||
right = right->left;
|
||||
}
|
||||
|
||||
return node->data;
|
||||
|
||||
}
|
||||
|
||||
// Releases all memory resources (including data copies).
|
||||
|
||||
Binary file not shown.
@ -1,2 +1,3 @@
|
||||
Silvana;9944
|
||||
hannes;9910
|
||||
player1;3999
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user