feat(linked list): implemented is empty function

This commit is contained in:
Mineplay 2025-04-25 16:11:13 -05:00
parent d89747a2ed
commit 34246c10d7
2 changed files with 8 additions and 1 deletions

View file

@ -25,6 +25,7 @@
#define FLEDASTY_LINKED_LIST #define FLEDASTY_LINKED_LIST
#include <stddef.h> #include <stddef.h>
#include <stdbool.h>
#include "../Utils/Error.h" #include "../Utils/Error.h"
@ -43,4 +44,6 @@ FledastyError fledasty_linked_list_destroy(FledastyLinkedList *current_linked_li
FledastyError fledasty_linked_list_append(FledastyLinkedList *current_linked_list, void *value); FledastyError fledasty_linked_list_append(FledastyLinkedList *current_linked_list, void *value);
static inline bool fledasty_linked_list_is_empty(FledastyLinkedList *current_linked_list) { return current_linked_list->size == 0; }
#endif #endif

View file

@ -111,11 +111,15 @@ int main() {
} }
FledastyLinkedListNode *test_linked_list_node = test_linked_list.start; FledastyLinkedListNode *test_linked_list_node = test_linked_list.start;
for (int i = 0; i < test_linked_list.size; i++) { for (int i = 0; i < test_linked_list.size; i += 1) {
printf("Linked list get: %d\n", *(int*)test_linked_list_node->value); printf("Linked list get: %d\n", *(int*)test_linked_list_node->value);
test_linked_list_node = test_linked_list_node->next; test_linked_list_node = test_linked_list_node->next;
} }
if (fledasty_linked_list_is_empty(&test_linked_list)) {
printf("Linked list is empty\n");
}
fledasty_linked_list_destroy(&test_linked_list); fledasty_linked_list_destroy(&test_linked_list);
printf("Done\n"); printf("Done\n");
return 0; return 0;