diff --git a/stack.c b/stack.c index 209089f62fb348a0d4779d667f6aba8bc2a0c1a1..4e59e8ffd8d72903f9987b1d0e49a498c79088f3 100644 --- a/stack.c +++ b/stack.c @@ -1,7 +1,3 @@ -#include <stdlib.h> -#include <stdbool.h> -#include <stdio.h> - #include "stack.h" @@ -87,4 +83,15 @@ int get_length(stack s) { bool stack_is_empty(stack s) { return s.top == -1; +} + +/** + * @brief Reset the stack's top to -1 + * New values will overwrite the old ones + * + * @param s + */ +void stack_clear(stack *s) +{ + s->top = -1; } \ No newline at end of file diff --git a/stack.h b/stack.h index 5aa60b4888579fba047ae8a656f61b86846b39bf..371cb4d127f380757b9d887fd2396939f6dc5755 100644 --- a/stack.h +++ b/stack.h @@ -1,3 +1,7 @@ +#include <stdlib.h> +#include <stdbool.h> +#include <stdio.h> + #ifndef _STACK_H_ #define _STACK_H_ @@ -17,6 +21,7 @@ void stack_peek(stack s, int *value); void stack_clone(stack s, stack *clone); int get_length(stack s); bool stack_is_empty(stack s); +void stack_clear(stack *s) ; void stack_print(const stack s);