diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index ca5349d..bd17de3 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -42,6 +42,8 @@ FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value); void *fledasty_stack_peek(const FledastyStack *current_stack); void *fledasty_stack_pop(FledastyStack *current_stack); +FledastyError fledasty_stack_clear(FledastyStack *current_stack); + static inline bool fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack->size == 0; } #endif diff --git a/Src/Core/Stack.c b/Src/Core/Stack.c index fd13ec9..916ff04 100644 --- a/Src/Core/Stack.c +++ b/Src/Core/Stack.c @@ -107,3 +107,12 @@ void *fledasty_stack_pop(FledastyStack *current_stack) { return value_address; } + +FledastyError fledasty_stack_clear(FledastyStack *current_stack) { + if (current_stack == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + current_stack->size = 0; + return FLEDASTY_ERROR_NONE; +} diff --git a/Tests/Main.c b/Tests/Main.c index cb241b1..3489d3b 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -67,6 +67,7 @@ int main() { printf("Stack popped: %d\n", *popped_data); } + fledasty_stack_clear(&test_stack); if (fledasty_stack_is_empty(&test_stack)) { printf("Stack is empty\n"); }