String Linked List Add function

TASKS_sll_add function now adds node to end of linked list
main
lomna 1 year ago
parent dc70c4452d
commit 0c3d26e838

@ -1,3 +1,3 @@
*Compile *Compile
#do #do
gcc -o tasks -I src src/tasks.c gcc -g -o tasks -I src src/tasks.c

@ -29,8 +29,18 @@ void TASKS_sll_print(TASKS_str_linked_list *list){
void TASKS_sll_add(TASKS_str_linked_list **list, char *s){ void TASKS_sll_add(TASKS_str_linked_list **list, char *s){
TASKS_str_linked_list *node = (TASKS_str_linked_list *) malloc(sizeof(TASKS_str_linked_list)); TASKS_str_linked_list *node = (TASKS_str_linked_list *) malloc(sizeof(TASKS_str_linked_list));
node->data = s; node->data = s;
node->next = *list; node->next = NULL;
TASKS_str_linked_list *iterator = *list;
if (iterator == NULL){
//This is the first element added to list
*list = node; *list = node;
return;
}
while(iterator->next != NULL)
iterator = iterator->next;
iterator->next = node;
} }
// The length values will also count \0 // The length values will also count \0

Loading…
Cancel
Save