function push is done
This commit is contained in:
parent
04c1328230
commit
bc6ec040b7
7
stack.c
7
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
|
||||
|
||||
10
stack.h
10
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user