Top Funktion des Stacks implementiert

This commit is contained in:
silvana884 2025-12-03 13:59:24 +01:00
parent fc5f249554
commit 09db456716
3 changed files with 19 additions and 4 deletions

View File

@ -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
View File

@ -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

View File

@ -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.