diff --git a/Chains_across_the_Island/Fundamentals/basics/basics.c b/Chains_across_the_Island/Fundamentals/basics/basics.c index 93a59f9..c1db8ea 100644 --- a/Chains_across_the_Island/Fundamentals/basics/basics.c +++ b/Chains_across_the_Island/Fundamentals/basics/basics.c @@ -5,6 +5,15 @@ struct list *list_append(struct list *l, int e) { + + struct list *new_node = malloc(sizeof(struct list)); + if(!new_node) return NULL; + + new_node->data = e; + new_node->next = l; + + return new_node; +/* struct list *tmp = l; struct list *new_node = calloc(1, sizeof(struct list)); @@ -16,7 +25,7 @@ struct list *list_append(struct list *l, int e) while (tmp->next != NULL) tmp = tmp->next; tmp->next = new_node; return l; - + */ } size_t list_count(struct list *l){ @@ -162,26 +171,23 @@ void list_print(struct list *l){ } printf("\n"); } -/* + int main(void) { struct list *l = NULL; - l = list_append(l, 42); // l = [42] -> NULL - list_print(l); - l = list_append(l, 7); // l = [7] -> [42] -> NULL - list_print(l); + l = list_append(l, 3); + l = list_append(l, 2); + l = list_append(l, 1); - // l = [1] -> [2] -> [3] + // l = [1] -> [2] -> [3] list_insert(&l, 1, 99); // l = [1] -> [99] -> [2] -> [3], and list_insert returns 0 list_insert(&l, 9, 99); // list unchanged, returns 1 + list_print(l); - list_count(NULL); // 0 - printf("count : %li\n",list_count(l)); // 3 - list_destroy(l); return 0; } -*/ + diff --git a/Chains_across_the_Island/Fundamentals/basics/test b/Chains_across_the_Island/Fundamentals/basics/test index ed2beca..cd45458 100755 Binary files a/Chains_across_the_Island/Fundamentals/basics/test and b/Chains_across_the_Island/Fundamentals/basics/test differ