feat(stack): added is empty function to stack

This commit is contained in:
Mineplay 2025-04-23 05:11:25 -05:00
parent b9006ebb0f
commit 47f7db53bb
3 changed files with 7 additions and 1 deletions

View file

@ -42,6 +42,6 @@ FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value);
void *fledasty_queue_peek(FledastyQueue *current_queue); void *fledasty_queue_peek(FledastyQueue *current_queue);
void *fledasty_queue_pop(FledastyQueue *current_queue); void *fledasty_queue_pop(FledastyQueue *current_queue);
static inline size_t fledasty_queue_is_empty(FledastyQueue *current_queue) { return current_queue->size == 0; } static inline size_t fledasty_queue_is_empty(const FledastyQueue *current_queue) { return current_queue->size == 0; }
#endif #endif

View file

@ -37,4 +37,6 @@ typedef struct {
FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size); FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size);
FledastyError fledasty_stack_destroy(FledastyStack *current_stack); FledastyError fledasty_stack_destroy(FledastyStack *current_stack);
static inline size_t fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack->size == 0; }
#endif #endif

View file

@ -48,6 +48,10 @@ int main() {
FledastyStack test_stack; FledastyStack test_stack;
fledasty_stack_initialize(&test_stack, sizeof(int)); fledasty_stack_initialize(&test_stack, sizeof(int));
if (fledasty_stack_is_empty(&test_stack)) {
printf("Stack is empty\n");
}
fledasty_stack_destroy(&test_stack); fledasty_stack_destroy(&test_stack);
printf("Done\n"); printf("Done\n");