some lst changes

This commit is contained in:
Jack Halford 2016-09-12 01:51:07 +02:00
parent ffe53b159f
commit e078fcbdd4
7 changed files with 75 additions and 10 deletions

View file

@ -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;
}
}

View file

@ -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;

View 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;
}
}
}

View file

@ -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;
}

View 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);
}

View file

@ -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;
}

View file

@ -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);