This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
prog-104-p-05-2030/The-Nook-GamesTM/Proficiencies/stack.c
T
2026-04-20 20:09:16 +02:00

36 lines
609 B
C

#include "stack.h"
struct stack *stack_push(struct stack *s, struct expression_element e)
{
struct stack *new = malloc(sizeof(struct stack));
new->next = NULL;
new->data = e;
if (s == NULL)
return new;
new->next = s;
return new;
}
struct stack *stack_pop(struct stack *s)
{
if (!s)
return NULL;
struct stack *next = s->next;
free(s);
return next;
}
void stack_destroy(struct stack **s)
{
if(!s)
return;
while (*s)
{
*s = stack_pop(*s);
}
}
struct expression_element stack_peek(struct stack *s)
{
return s->data;
}