diff --git a/stack.c b/stack.c index fc4205b03f83906530ccc57a6e49d70d1683bb95..209089f62fb348a0d4779d667f6aba8bc2a0c1a1 100644 --- a/stack.c +++ b/stack.c @@ -1,4 +1,7 @@ #include <stdlib.h> +#include <stdbool.h> +#include <stdio.h> + #include "stack.h" @@ -75,3 +78,13 @@ int get_length(stack s) { return s.top + 1; } +/** + * @brief Check if a stack is empty + * + * @param s + * @return bool - true if stack is empty, false otherwise + */ +bool stack_is_empty(stack s) +{ + return s.top == -1; +} \ No newline at end of file diff --git a/stack.h b/stack.h index 010bfdc0153b05dbe62b975fe51830c6ac26f26e..5aa60b4888579fba047ae8a656f61b86846b39bf 100644 --- a/stack.h +++ b/stack.h @@ -1,7 +1,6 @@ #ifndef _STACK_H_ #define _STACK_H_ - typedef struct _stack { int *data; int capacity; @@ -17,6 +16,7 @@ void stack_pop(stack *s, int *value); 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_print(const stack s);