aboutsummaryrefslogtreecommitdiff
path: root/stack.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-14 12:13:01 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-14 12:13:01 +0300
commit365f1baabae9b2ccb3df1b4a4821bff58611f2de (patch)
treeffe39de1013bab314f2bb64f68d0e368a3fe3493 /stack.c
parent90f365e0ff8cff6bc426d08a04a0ede63379fc3b (diff)
implement a PositionStack
Diffstat (limited to 'stack.c')
-rw-r--r--stack.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/stack.c b/stack.c
new file mode 100644
index 0000000..bcdfbd3
--- /dev/null
+++ b/stack.c
@@ -0,0 +1,23 @@
+#include "stack.h"
+#include "structs.h"
+
+PositionStack ps_new(void) {
+ PositionStack ps;
+ ps.top = 0;
+ return ps;
+}
+
+int ps_push(PositionStack ps, Position pos) {
+ ps.arr[ps.top] = pos;
+ ps.top += 1;
+}
+
+Position ps_pop(PositionStack ps) {
+ ps.top -= 1;
+ return ps.arr[ps.top];
+}
+
+Position ps_peek(PositionStack ps) {
+ return ps.arr[ps.top - 1];
+}
+