function push is done

This commit is contained in:
regis37 2025-11-26 22:52:32 +01:00
parent 04c1328230
commit bc6ec040b7
2 changed files with 10 additions and 7 deletions

View File

@ -10,7 +10,12 @@
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data)
{
StackNode *newNode = (StackNode *)malloc(sizeof(StackNode));
if(newNode == NULL)
return NULL;
newNode->data = data;
newNode->next = stack;
return newNode;
}
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be

10
stack.h
View File

@ -10,12 +10,10 @@ The latest element is taken from the stack. */
//TODO: passenden Datentyp als struct anlegen
typedef struct Node{
int *data;
struct Node *next;
} StackNode;
typedef struct StackNode {
void *data;
struct StackNode *next;
} StackNode;
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data);