merged 42sh stuff that wasnt in the submodule
This commit is contained in:
parent
cb2e66e0c6
commit
0aef582882
4 changed files with 51 additions and 12 deletions
|
|
@ -79,6 +79,7 @@ lst/ft_lst_cfree.c\
|
|||
lst/ft_lst_delif.c\
|
||||
lst/ft_lst_delsub.c\
|
||||
lst/ft_lst_filter.c\
|
||||
lst/ft_lst_filterout.c\
|
||||
lst/ft_lst_find.c\
|
||||
lst/ft_lst_merge.c\
|
||||
lst/ft_lst_order_delsub.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 20:09:05 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/28 20:34:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,13 +26,12 @@ typedef struct s_list t_list;
|
|||
|
||||
int pop(t_list **lst);
|
||||
t_list *push(t_list **stack, int elem);
|
||||
int top(t_list *top);
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstadd(t_list **alst, t_list *new);
|
||||
int ft_lstiter(t_list *lst, int (*f)());
|
||||
int ft_lstiter(t_list *lst, int (*f)(), void *data);
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *));
|
||||
|
||||
t_list *ft_lstnew_range(int a, int b);
|
||||
|
|
@ -76,6 +75,11 @@ t_list *ft_lst_find(
|
|||
t_list *ft_lstpop(t_list **lst);
|
||||
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2);
|
||||
void ft_lst_reverse(t_list **begin_list);
|
||||
void ft_lst_filterout(
|
||||
t_list **alst,
|
||||
void *data_ref,
|
||||
int (*cmp)(),
|
||||
void (*del)(void *, size_t));
|
||||
|
||||
int ft_diff(void *a, void *b);
|
||||
t_list *ft_id(t_list *a);
|
||||
|
|
|
|||
36
libft/srcs/lst/ft_lst_filterout.c
Normal file
36
libft/srcs/lst/ft_lst_filterout.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lst_filterout.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/26 16:56:02 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/26 19:10:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lst_filterout(
|
||||
t_list **alst,
|
||||
void *data_ref,
|
||||
int (*cmp)(),
|
||||
void (*del)(void *, size_t))
|
||||
{
|
||||
t_list *tmp;
|
||||
t_list **indirect;
|
||||
|
||||
indirect = alst;
|
||||
while (*indirect)
|
||||
{
|
||||
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||
{
|
||||
tmp = *indirect;
|
||||
(*indirect) = (*indirect)->next;
|
||||
ft_lstdelone(&tmp, del);
|
||||
}
|
||||
else
|
||||
indirect = &(*indirect)->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,19 +6,17 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/11 16:17:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/28 11:27:45 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstiter(t_list *lst, int (*f)())
|
||||
int ft_lstiter(t_list *lst, int (*f)(), void *data)
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
if ((*f)(lst->content))
|
||||
return (1);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (0);
|
||||
if (!lst)
|
||||
return (0);
|
||||
if ((*f)(lst->content, data))
|
||||
return (1);
|
||||
return (ft_lstiter(lst->next, f, data));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue