f4-basic-linked-list #19

Merged
Mineplay merged 13 commits from f4-basic-linked-list into main 2025-04-26 07:41:38 -05:00
3 changed files with 23 additions and 1 deletions
Showing only changes of commit 9d571c694e - Show all commits

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

@ -86,3 +86,19 @@ 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;