diff --git a/stack.c b/stack.c index aa8a34ee019f6eb04b6602fe070f2fbd72a1bd88..6605c16cc53c3714c81e1e45018932da457b3aba 100644 --- a/stack.c +++ b/stack.c @@ -11,6 +11,13 @@ void stack_init(stack *s) s->data = malloc(sizeof(int) * DEFAULT_CAPACITY); } +void stack_destroy(stack *s){ + free(s->data); + s->data = NULL; + s->capacity = -1; + s->top = -1; +} + void stack_peek(stack s, int *value){ if (!stack_is_empty(s)) { *value = s.data[s.top]; diff --git a/stack.h b/stack.h index fc3bc04697bb7e9e90cd32b17f8e3c161c92247b..6ccd51b31d92bf77538a2a733aba1d927f2f8120 100644 --- a/stack.h +++ b/stack.h @@ -9,6 +9,8 @@ typedef struct _stack { void stack_init(stack *stack); +void stack_destroy(stack *s); + void stack_peek(stack s, int *value); void stack_clone(stack s, stack *clone); int get_length(stack s);