From bc6ec040b7799f29bdae752a6ec4d1eb2eb03f7b Mon Sep 17 00:00:00 2001 From: regis37 Date: Wed, 26 Nov 2025 22:52:32 +0100 Subject: [PATCH] function push is done --- stack.c | 7 ++++++- stack.h | 10 ++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/stack.c b/stack.c index e3a90d4..c425534 100644 --- a/stack.c +++ b/stack.c @@ -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 diff --git a/stack.h b/stack.h index b379424..db5446c 100644 --- a/stack.h +++ b/stack.h @@ -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);