diff --git a/Chains_across_the_Island/Fundamentals/basics/basics.c b/Chains_across_the_Island/Fundamentals/basics/basics.c index 1650825..3c6ecde 100644 --- a/Chains_across_the_Island/Fundamentals/basics/basics.c +++ b/Chains_across_the_Island/Fundamentals/basics/basics.c @@ -53,9 +53,12 @@ int list_insert(struct list **l, size_t index, int e){ if(index == 0){ + *l = list_append(*l, e); + /* new_node->data = e; new_node->next = *l; *l = new_node; + */ return 0; } diff --git a/Chains_across_the_Island/Fundamentals/double/double.c b/Chains_across_the_Island/Fundamentals/double/double.c index d17ec7a..fc2b016 100644 --- a/Chains_across_the_Island/Fundamentals/double/double.c +++ b/Chains_across_the_Island/Fundamentals/double/double.c @@ -20,13 +20,19 @@ struct dlist *dlist_append(struct dlist *l, int e) int dlist_insert(struct dlist **l, size_t index, int e) { - struct dlist *tmp = *l; + if(!l) return 1; + + struct dlist *new_node = malloc(sizeof(struct dlist)); + if(!new_node) return 1; + + //struct dlist *tmp = *l; if(index == 0){ dlist_append(*l, e); return 0; } + struct dlist *tmp = *l; size_t ind = 0; while(tmp != NULL && ind < index - 1){ @@ -36,8 +42,8 @@ int dlist_insert(struct dlist **l, size_t index, int e) if(!tmp) return 1; - struct dlist *new_node = malloc(sizeof(struct dlist)); - if(!new_node) return 1; + //struct dlist *new_node = malloc(sizeof(struct dlist)); + //if(!new_node) return 1; new_node->data = e; new_node->next = tmp;