aboutsummaryrefslogtreecommitdiff
path: root/stack.c
blob: c915afdfc037ea07a954e35a12f81e007a15588e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "stack.h"
#include "structs.h"

PositionStack ps_new(void) {
    PositionStack ps;
    ps.top = 0;
    return ps;
}

int ps_push(PositionStack *ps, Position pos) {
    /*TODO: check for stack overflow */
    ps->arr[ps->top] = pos;
    ps->top += 1;
    return 0;
}

Position ps_pop(PositionStack *ps) {
    ps->top -= 1;
    return ps->arr[ps->top];
}

Position ps_peek(PositionStack ps) {
    return ps.arr[ps.top - 1];
}