add lstremove_next and lstadd_back now return
This commit is contained in:
@@ -6,13 +6,14 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
** or first if list has no element so far
|
||||
** add an element to the end of a list, or first if list has no element yet
|
||||
** 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"
|
||||
|
||||
void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
void *ft_lstadd_back(t_list **alst, t_list *new)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (!new)
|
||||
return (NULL);
|
||||
if (alst)
|
||||
{
|
||||
tmp = *alst;
|
||||
@@ -87,4 +90,5 @@ void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
tmp->next = new;
|
||||
}
|
||||
}
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
lst = (t_list *)malloc(sizeof(*lst));
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
if (!content)
|
||||
lst->content = NULL;
|
||||
else
|
||||
lst->content = content;
|
||||
lst->content = content;
|
||||
lst->next = NULL;
|
||||
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