diff --git a/libftasm/ft_lst_delsub.c b/libftasm/ft_lst_delsub.c index 1d57c477..ef83d859 100644 --- a/libftasm/ft_lst_delsub.c +++ b/libftasm/ft_lst_delsub.c @@ -11,11 +11,6 @@ void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, tmp = NULL; while (current && sub) { - if ((*cmp)(current->content, sub->content) > 0) - { - sub = sub->next; - continue ; - } if ((*cmp)(current->content, sub->content) == 0) { if (current == *alst) @@ -32,5 +27,7 @@ void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, last = current; current = current->next; } + if (!current && sub) + current = *alst; } } diff --git a/libftasm/ft_lst_find.c b/libftasm/ft_lst_find.c index 716ec65e..26eaed05 100644 --- a/libftasm/ft_lst_find.c +++ b/libftasm/ft_lst_find.c @@ -1,9 +1,6 @@ #include "libft.h" -t_list *ft_list_find( - t_list *begin_list, - void *data_ref, - int (*cmp)()) +t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)()) { t_list *list_ptr; diff --git a/libftasm/ft_lst_order_delsub.c b/libftasm/ft_lst_order_delsub.c new file mode 100644 index 00000000..1d57c477 --- /dev/null +++ b/libftasm/ft_lst_order_delsub.c @@ -0,0 +1,36 @@ +#include "libft.h" + +void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, size_t)) +{ + t_list *last; + t_list *current; + t_list *tmp; + + last = NULL; + current = *alst; + tmp = NULL; + while (current && sub) + { + if ((*cmp)(current->content, sub->content) > 0) + { + sub = sub->next; + continue ; + } + if ((*cmp)(current->content, sub->content) == 0) + { + if (current == *alst) + *alst = current->next; + else + last->next = current->next; + tmp = current; + current = current->next; + sub = sub->next; + ft_lstdelone(&tmp, del); + } + else + { + last = current; + current = current->next; + } + } +} diff --git a/libftasm/ft_lst_print.c b/libftasm/ft_lst_print.c index f681f06d..dbd9d83f 100644 --- a/libftasm/ft_lst_print.c +++ b/libftasm/ft_lst_print.c @@ -5,7 +5,7 @@ void ft_lst_print(t_list *list, void (*printer)()) while (list) { ft_putstr("["); - (*printer)(*(int *)list->content); + (*printer)(list->content); ft_putstr("]->"); list = list->next; } diff --git a/libftasm/ft_lst_removeif.c b/libftasm/ft_lst_removeif.c new file mode 100644 index 00000000..fe323ff7 --- /dev/null +++ b/libftasm/ft_lst_removeif.c @@ -0,0 +1,32 @@ +#include "libft.h" + +t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)()) +{ + t_list *last; + t_list *current; + t_list *tmp; + + last = NULL; + tmp = NULL; + current = *alst; + while (current) + { + if ((*cmp)(current->content, data_ref) == 0) + { + if (current == *alst) + *alst = current->next; + else + last->next = current->next; + tmp = current; + current = current->next; + return (tmp); + } + else + { + last = current; + current = current->next; + } + } + return (NULL); +} + diff --git a/libftasm/ft_lst_sorted_insert.c b/libftasm/ft_lst_sorted_insert.c index 40fcd2fd..b5e3cfa2 100644 --- a/libftasm/ft_lst_sorted_insert.c +++ b/libftasm/ft_lst_sorted_insert.c @@ -23,4 +23,5 @@ void ft_lst_sorted_insert(t_list **begin_list, t_list *insert, int (*cmp)()) link = link->next; } link->next = insert; + insert->next = NULL; } diff --git a/libftasm/libft.h b/libftasm/libft.h index e0efb934..d8b35651 100644 --- a/libftasm/libft.h +++ b/libftasm/libft.h @@ -93,6 +93,8 @@ void ft_lst_delif(t_list **alist, void *data_ref, int (*cmp)(), void (*del)(void void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, size_t)); void ft_lst_cfree(void *ptr, size_t size); t_list *ft_lst_filter(t_list *lst, void const *data_ref, t_list *(*f)(t_list *elem, void const *)); +t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)()); +t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)()); int ft_diff(void *a, void *b); t_list *ft_id(t_list *a);