summaryrefslogtreecommitdiff
path: root/rushs/tinyprintf/evalexpr/src/stack.c
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/tinyprintf/evalexpr/src/stack.c
add: graphs et rushs
Diffstat (limited to 'rushs/tinyprintf/evalexpr/src/stack.c')
-rw-r--r--rushs/tinyprintf/evalexpr/src/stack.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/rushs/tinyprintf/evalexpr/src/stack.c b/rushs/tinyprintf/evalexpr/src/stack.c
new file mode 100644
index 0000000..14f659e
--- /dev/null
+++ b/rushs/tinyprintf/evalexpr/src/stack.c
@@ -0,0 +1,57 @@
+#include "stack.h"
+
+#include <stdlib.h>
+
+struct stack *stack_push(struct stack *s, int e)
+{
+ struct stack *new = malloc(sizeof(struct stack));
+ new->data = e;
+ new->next = NULL;
+
+ new->next = s;
+ return new;
+}
+
+struct stack *stack_pop(struct stack *s)
+{
+ if (s == NULL)
+ {
+ return NULL;
+ }
+
+ struct stack *res = s->next;
+ free(s);
+ return res;
+}
+
+int stack_peek(struct stack *s)
+{
+ return s->data;
+}
+
+struct tstack *tstack_push(struct tstack *s, struct token *e)
+{
+ struct tstack *new = malloc(sizeof(struct tstack));
+ new->token = e;
+ new->next = NULL;
+
+ new->next = s;
+ return new;
+}
+
+struct tstack *tstack_pop(struct tstack *s)
+{
+ if (s == NULL)
+ {
+ return NULL;
+ }
+
+ struct tstack *res = s->next;
+ free(s);
+ return res;
+}
+
+struct token *tstack_peek(struct tstack *s)
+{
+ return s->token;
+}