From bec8b7b68eec8c10bd5155375ca9e93c1ea6915b Mon Sep 17 00:00:00 2001 From: "joey.martig" <joey.martig@etu.hesge.ch> Date: Wed, 1 Dec 2021 01:01:24 +0100 Subject: [PATCH] Resolve "Added destroy function" that frees the data and sets capacity and top to -1 --- stack.c | 7 +++++++ stack.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/stack.c b/stack.c index aa8a34e..6605c16 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 fc3bc04..6ccd51b 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); -- GitLab