This commit is contained in:
2026-04-20 20:09:16 +02:00
commit a97f290271
22 changed files with 451 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
#ifndef STACK_H
#define STACK_H
#include <stdlib.h>
union element_type
{
int operand;
char operator;
};
enum element_tag {
TOKEN_OPERAND,
TOKEN_OPERATOR
};
struct expression_element {
enum element_tag tag;
union element_type data;
};
struct stack {
struct expression_element data;
struct stack *next;
};
/* Push a new element to the stack and returns the new top */
struct stack *stack_push(struct stack *s, struct expression_element element);
/* Pop from the stack and returns its new top */
struct stack *stack_pop(struct stack *s);
/* Empty and frees the whole stack */
void stack_destroy(struct stack **s);
/* Returns the current top of the stack */
struct expression_element stack_peek(struct stack *s);
#endif /* ! STACK_H */