add lstremove_next and lstadd_back now return
This commit is contained in:
3
Makefile
3
Makefile
@@ -120,7 +120,8 @@ SRCS = ft_memset.c \
|
|||||||
ft_sqrt.c \
|
ft_sqrt.c \
|
||||||
ft_free_tab.c \
|
ft_free_tab.c \
|
||||||
\
|
\
|
||||||
ft_arrintchr.c
|
ft_arrintchr.c \
|
||||||
|
ft_lstremove_next.c
|
||||||
|
|
||||||
|
|
||||||
ODIR = ./builds
|
ODIR = ./builds
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/11/25 14:45:53 by hulamy #+# #+# */
|
/* Created: 2019/11/25 14:45:53 by hulamy #+# #+# */
|
||||||
/* Updated: 2022/03/23 14:22:33 by simplonco ### ########.fr */
|
/* Updated: 2022/03/23 21:51:14 by simplonco ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -65,9 +65,9 @@ typedef struct s_list
|
|||||||
|
|
||||||
t_list *ft_lstnew(void *content);
|
t_list *ft_lstnew(void *content);
|
||||||
void ft_lstadd_front(t_list **alst, t_list *n);
|
void ft_lstadd_front(t_list **alst, t_list *n);
|
||||||
|
void *ft_lstadd_back(t_list **alst, t_list *n);
|
||||||
int ft_lstsize(t_list *lst);
|
int ft_lstsize(t_list *lst);
|
||||||
t_list *ft_lstlast(t_list *lst);
|
t_list *ft_lstlast(t_list *lst);
|
||||||
void ft_lstadd_back(t_list **alst, t_list *n);
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||||
@@ -114,5 +114,6 @@ int ft_sqrt(int i);
|
|||||||
void ft_free_tab(char **tab);
|
void ft_free_tab(char **tab);
|
||||||
|
|
||||||
int ft_arrintchr(int * intarr, int comp, size_t size);
|
int ft_arrintchr(int * intarr, int comp, size_t size);
|
||||||
|
void ft_lstremove_next(t_list *lst, void (*del)(void *));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,13 +6,14 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/11/25 14:11:53 by hulamy #+# #+# */
|
/* Created: 2019/11/25 14:11:53 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/11/25 14:36:12 by hulamy ### ########.fr */
|
/* Updated: 2022/03/23 21:50:42 by simplonco ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** add an element to the end of a list
|
** add an element to the end of a list, or first if list has no element yet
|
||||||
** or first if list has no element so far
|
** return NULL if element is NULL (eg, it returned from ft_lstnew and failed)
|
||||||
|
** or else address to the element added
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -71,10 +72,12 @@
|
|||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_lstadd_back(t_list **alst, t_list *new)
|
void *ft_lstadd_back(t_list **alst, t_list *new)
|
||||||
{
|
{
|
||||||
t_list *tmp;
|
t_list *tmp;
|
||||||
|
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
if (alst)
|
if (alst)
|
||||||
{
|
{
|
||||||
tmp = *alst;
|
tmp = *alst;
|
||||||
@@ -87,4 +90,5 @@ void ft_lstadd_back(t_list **alst, t_list *new)
|
|||||||
tmp->next = new;
|
tmp->next = new;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return (tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/11/25 14:16:20 by hulamy #+# #+# */
|
/* Created: 2019/11/25 14:16:20 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/11/25 14:29:46 by hulamy ### ########.fr */
|
/* Updated: 2022/03/23 20:24:40 by simplonco ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -48,12 +48,10 @@ t_list *ft_lstnew(void *content)
|
|||||||
{
|
{
|
||||||
t_list *lst;
|
t_list *lst;
|
||||||
|
|
||||||
if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
lst = (t_list *)malloc(sizeof(*lst));
|
||||||
|
if (!lst)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (!content)
|
lst->content = content;
|
||||||
lst->content = NULL;
|
|
||||||
else
|
|
||||||
lst->content = content;
|
|
||||||
lst->next = NULL;
|
lst->next = NULL;
|
||||||
return (lst);
|
return (lst);
|
||||||
}
|
}
|
||||||
|
|||||||
30
srcs/ft_lstremove_next.c
Normal file
30
srcs/ft_lstremove_next.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstremove_next.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/23 21:42:05 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/03/23 21:42:55 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* remove the next element of the list, delete its content, and free it
|
||||||
|
* then rejoin the list without this element
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstremove_next(t_list *lst, void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *next_tmp;
|
||||||
|
|
||||||
|
if (!lst || !lst->next || !del)
|
||||||
|
return ;
|
||||||
|
next_tmp = lst->next->next;
|
||||||
|
del(lst->next->content);
|
||||||
|
free(lst->next);
|
||||||
|
lst->next = next_tmp;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user