1
0

libft reformat

This commit is contained in:
Adam Joly
2024-02-04 15:11:02 +01:00
parent 6486eb4b3f
commit 45b737cf5f
64 changed files with 730 additions and 205 deletions

25
lst/ft_lstadd_back.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 16:37:42 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:56:37 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
if (!lst)
return ;
if (!*lst)
{
(*lst) = new;
return ;
}
ft_lstlast((*lst))->next = new;
}

23
lst/ft_lstadd_front.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:39:25 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:57:01 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (!lst)
return ;
if (!new)
return ;
new->next = *lst;
*lst = new;
}

26
lst/ft_lstclear.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:05:14 by adjoly #+# #+# */
/* Updated: 2024/02/04 13:55:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
tmp = NULL;
while (lst && *lst && del)
{
tmp = (*lst)->next;
ft_lstdelone((*lst), del);
*lst = tmp;
}
}

21
lst/ft_lstdelone.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 17:59:39 by adjoly #+# #+# */
/* Updated: 2024/02/04 13:55:19 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (lst == NULL || del == NULL)
return ;
del(lst->content);
free(lst);
}

24
lst/ft_lstiter.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:20:25 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:58:16 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}

22
lst/ft_lstlast.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 16:03:12 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:57:50 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_list *ft_lstlast(t_list *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}

35
lst/ft_lstmap.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:24:49 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:58:45 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *res;
t_list *tmp;
if (!lst || !f || !del)
return (NULL);
res = NULL;
while (lst)
{
tmp = ft_lstnew(f(lst->content));
if (tmp == NULL)
{
ft_lstclear(&tmp, del);
return (NULL);
}
ft_lstadd_back(&res, tmp);
lst = lst->next;
}
return (res);
}

25
lst/ft_lstnew.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:30:32 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:58:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_list *ft_lstnew(void *content)
{
t_list *lst;
lst = malloc(sizeof(t_list));
if (!lst)
return (NULL);
lst[0].content = content;
lst[0].next = NULL;
return (lst);
}

26
lst/ft_lstsize.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:53:01 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:59:13 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_lstsize(t_list *lst)
{
int i;
i = 0;
while (lst)
{
lst = lst->next;
i++;
}
return (i);
}