diff --git a/stack.c b/stack.c index 82311dd6dd1deb2e0b0f8af59674e62e8657be7a..a42d51e7b410febca7ff32be2bc7b1c83b53cd99 100644 --- a/stack.c +++ b/stack.c @@ -1,11 +1,14 @@ // depile void stack_pop(stack *s, int *value){ - assert(s->top>=0 && "Stcak is empty\n"); - + if (stack_is_empty(*s)){ + printf("stack is empty\n"); + return; + } if (s->top == s->capacity/4){ s->capacity /= 2; + s->data = realloc(s->data, sizeof(int)*s->capacity); } - + *value = s->data[s->top]; s->top -= 1; } \ No newline at end of file diff --git a/stack.h b/stack.h new file mode 100644 index 0000000000000000000000000000000000000000..e307bf6a2209ee301825b825ad6536cf44eea51b --- /dev/null +++ b/stack.h @@ -0,0 +1 @@ +void stack_pop(stack *s, int *value);