feat(stack): implemented clear function
This commit is contained in:
parent
0dfa753a56
commit
3c8cc19cab
3 changed files with 12 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue