From 365f1baabae9b2ccb3df1b4a4821bff58611f2de Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Sat, 14 Mar 2026 12:13:01 +0300 Subject: implement a PositionStack --- stack.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 stack.c (limited to 'stack.c') 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]; +} + -- cgit v1.2.3