generated from freudenreichan/info2Praktikum-DobleSpiel
Top Funktion des Stacks implementiert
This commit is contained in:
parent
fc5f249554
commit
09db456716
@ -66,15 +66,21 @@ 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)
|
||||||
{
|
{
|
||||||
|
if(root == NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
stackNode.top(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Releases all memory resources (including data copies).
|
// Releases all memory resources (including data copies).
|
||||||
void clearTree(TreeNode *root)
|
void clearTree(TreeNode *root)
|
||||||
{
|
{
|
||||||
if (root == NULL)
|
if (root == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
// Erst linken Knoten löschen
|
// Erst linken Knoten löschen
|
||||||
clearTree(root->left);
|
clearTree(root->left);
|
||||||
|
|
||||||
|
|||||||
12
stack.c
12
stack.c
@ -10,7 +10,17 @@
|
|||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
StackNode *push(StackNode *stack, void *data)
|
StackNode *push(StackNode *stack, void *data)
|
||||||
{
|
{
|
||||||
|
if(stack && data){
|
||||||
|
StackNode *t = (StackNode *)malloc(sizeof(StackNode));
|
||||||
|
if(!t)
|
||||||
|
{
|
||||||
|
return NULL; //Speicherfehler
|
||||||
|
}
|
||||||
|
t->prev = stack;
|
||||||
|
t->data = data;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||||
|
|||||||
3
stack.h
3
stack.h
@ -10,8 +10,7 @@ The latest element is taken from the stack. */
|
|||||||
//TODO: passenden Datentyp als struct anlegen
|
//TODO: passenden Datentyp als struct anlegen
|
||||||
typedef{
|
typedef{
|
||||||
int* data;
|
int* data;
|
||||||
unsigned int *fol;
|
struct StackNode *prev;
|
||||||
unsigned int *prev;
|
|
||||||
}StackNode;
|
}StackNode;
|
||||||
|
|
||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user