some lst changes
This commit is contained in:
parent
e590988c7d
commit
10ffa678ac
7 changed files with 75 additions and 10 deletions
|
|
@ -11,11 +11,6 @@ void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *,
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
while (current && sub)
|
while (current && sub)
|
||||||
{
|
{
|
||||||
if ((*cmp)(current->content, sub->content) > 0)
|
|
||||||
{
|
|
||||||
sub = sub->next;
|
|
||||||
continue ;
|
|
||||||
}
|
|
||||||
if ((*cmp)(current->content, sub->content) == 0)
|
if ((*cmp)(current->content, sub->content) == 0)
|
||||||
{
|
{
|
||||||
if (current == *alst)
|
if (current == *alst)
|
||||||
|
|
@ -32,5 +27,7 @@ void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *,
|
||||||
last = current;
|
last = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
if (!current && sub)
|
||||||
|
current = *alst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
t_list *ft_list_find(
|
t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)())
|
||||||
t_list *begin_list,
|
|
||||||
void *data_ref,
|
|
||||||
int (*cmp)())
|
|
||||||
{
|
{
|
||||||
t_list *list_ptr;
|
t_list *list_ptr;
|
||||||
|
|
||||||
|
|
|
||||||
36
libft/ft_lst_order_delsub.c
Normal file
36
libft/ft_lst_order_delsub.c
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ void ft_lst_print(t_list *list, void (*printer)())
|
||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
ft_putstr("[");
|
ft_putstr("[");
|
||||||
(*printer)(*(int *)list->content);
|
(*printer)(list->content);
|
||||||
ft_putstr("]->");
|
ft_putstr("]->");
|
||||||
list = list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
libft/ft_lst_removeif.c
Normal file
32
libft/ft_lst_removeif.c
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -23,4 +23,5 @@ void ft_lst_sorted_insert(t_list **begin_list, t_list *insert, int (*cmp)())
|
||||||
link = link->next;
|
link = link->next;
|
||||||
}
|
}
|
||||||
link->next = insert;
|
link->next = insert;
|
||||||
|
insert->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, size_t));
|
||||||
void ft_lst_cfree(void *ptr, size_t size);
|
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_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);
|
int ft_diff(void *a, void *b);
|
||||||
t_list *ft_id(t_list *a);
|
t_list *ft_id(t_list *a);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue