generated from freudenreichan/info2Praktikum-DobleSpiel
34 lines
629 B
C
34 lines
629 B
C
#include <stdlib.h>
|
|
#include "stack.h"
|
|
|
|
StackNode *push(StackNode *stack, void *data)
|
|
{
|
|
StackNode *node = malloc(sizeof(StackNode));
|
|
if (node == NULL) return stack;
|
|
node->data = data;
|
|
node->next = stack;
|
|
return node;
|
|
}
|
|
|
|
StackNode *pop(StackNode *stack)
|
|
{
|
|
if (stack == NULL) return NULL;
|
|
StackNode *next = stack->next;
|
|
free(stack);
|
|
return next;
|
|
}
|
|
|
|
void *top(StackNode *stack)
|
|
{
|
|
if (stack == NULL) return NULL;
|
|
return stack->data;
|
|
}
|
|
|
|
void clearStack(StackNode *stack)
|
|
{
|
|
while (stack != NULL) {
|
|
StackNode *next = stack->next;
|
|
free(stack);
|
|
stack = next;
|
|
}
|
|
} |