diff options
| -rw-r--r-- | stack.c | 3 | ||||
| -rw-r--r-- | stack.h | 5 |
2 files changed, 4 insertions, 4 deletions
@@ -12,14 +12,13 @@ PositionStack ps_new(void) { return ps; } -int ps_push(PositionStack *ps, Position pos) { +void ps_push(PositionStack *ps, Position pos) { if (ps->top >= ps->capacity) { ps->capacity *= STACK_SIZE_COEFFICIENT; if ((ps->arr = realloc(ps->arr, sizeof(Position) * ps->capacity)) == NULL) error("Failed to realloc ps->arr\n"); } ps->arr[ps->top] = pos; ps->top += 1; - return 0; } Position ps_pop(PositionStack *ps) { @@ -10,12 +10,13 @@ struct PositionStack_s { Position *arr; /* The array with all the values */ size_t capacity; - size_t top; /* Shows where the top of the stack is */ + size_t top; /* Shows where the top of the stack is. + * Points to the empty spot after the last element */ }; typedef struct PositionStack_s PositionStack; PositionStack ps_new(void); /* Returns an empty position stack */ -int ps_push(PositionStack *ps, Position pos); /* Returns -1 if failed to realloc() */ +void ps_push(PositionStack *ps, Position pos); /* Returns -1 if failed to realloc() */ Position ps_pop(PositionStack *ps); Position ps_peek(PositionStack ps); void ps_free(PositionStack ps); |
