diff --git a/Chains_across_the_Island/Fundamentals/basics/basics.c b/Chains_across_the_Island/Fundamentals/basics/basics.c index 40b9036..0ddaa6d 100644 --- a/Chains_across_the_Island/Fundamentals/basics/basics.c +++ b/Chains_across_the_Island/Fundamentals/basics/basics.c @@ -87,6 +87,7 @@ struct list *list_get(struct list *l, size_t index){ tmp = tmp->next; ind ++; } + if(ind >= index) return NULL; return tmp; @@ -96,7 +97,9 @@ struct list *list_get(struct list *l, size_t index){ void list_destroy(struct list *l){ if (!l) return; + list_destroy(l->next); + free(l); } @@ -151,7 +154,7 @@ int list_remove(struct list **l, int e){ tmp = tmp->next; } - if (!tmp) return NULL; + if (!tmp) return 0; if(!old) *l = tmp->next; else old->next = tmp->next;