feat(linked list): added append function

This commit is contained in:
Mineplay 2025-04-25 15:18:44 -05:00
parent ffdb897cda
commit 9d571c694e
3 changed files with 23 additions and 1 deletions

View file

@ -41,4 +41,6 @@ typedef struct {
FledastyError fledasty_linked_list_initialize(FledastyLinkedList *new_linked_list, void *values, const size_t values_size, const size_t element_byte_size);
FledastyError fledasty_linked_list_destroy(FledastyLinkedList *current_linked_list);
FledastyError fledasty_linked_list_append(FledastyLinkedList *current_linked_list, void *value);
#endif

View file

@ -85,4 +85,20 @@ FledastyError fledasty_linked_list_destroy(FledastyLinkedList *current_linked_li
}
return FLEDASTY_ERROR_NONE;
}
}
FledastyError fledasty_linked_list_append(FledastyLinkedList *current_linked_list, void *value) {
if (current_linked_list == NULL || value == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
FledastyLinkedListNode *new_node = (FledastyLinkedListNode*)hallocy_malloc(sizeof(FledastyLinkedListNode));
new_node->value = hallocy_malloc(current_linked_list->element_byte_size);
hallocy_copy_memory(new_node->value, value, current_linked_list->element_byte_size);
new_node->next = NULL;
current_linked_list->end->next = new_node;
return FLEDASTY_ERROR_NONE;
}

View file

@ -106,6 +106,10 @@ int main() {
FledastyLinkedList test_linked_list;
fledasty_linked_list_initialize(&test_linked_list, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int));
for (int i = 0; i < 10; i += 1) {
fledasty_linked_list_append(&test_linked_list, &i);
}
fledasty_linked_list_destroy(&test_linked_list);
printf("Done\n");
return 0;