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.
void *nextTreeData(TreeNode *root)
{
if(root == NULL)
{
}
stackNode.top(root);
}
// Releases all memory resources (including data copies).
void clearTree(TreeNode *root)
{
if (root == NULL)
{
return;
}
// Erst linken Knoten löschen
clearTree(root->left);

12
stack.c
View File

@ -10,7 +10,17 @@
// Pushes data as pointer onto the stack.
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

View File

@ -10,8 +10,7 @@ The latest element is taken from the stack. */
//TODO: passenden Datentyp als struct anlegen
typedef{
int* data;
unsigned int *fol;
unsigned int *prev;
struct StackNode *prev;
}StackNode;
// Pushes data as pointer onto the stack.