This commit is contained in:
mcolonna 2024-04-24 22:02:42 +02:00
parent e5371d0197
commit e438fea669
434 changed files with 41314 additions and 14135 deletions

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <smaccary@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/11 16:50:17 by smaccary #+# #+# */
/* Updated: 2020/06/13 15:21:25 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
void ft_lstadd_back(t_list **alst, t_list *new)
{
t_list *last;
if (!*alst)
{
*alst = new;
return ;
}
last = ft_lstlast(*alst);
last->next = new;
}

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/11 16:32:36 by smaccary #+# #+# */
/* Updated: 2019/11/17 16:56:05 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
void ft_lstadd_front(t_list **alst, t_list *new)
{
if (!alst || !new)
return ;
new->next = *alst;
*alst = new;
}

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <smaccary@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/11 16:39:19 by smaccary #+# #+# */
/* Updated: 2020/07/31 21:44:24 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
t_list *ft_lstchr(t_list *lst, void *find)
{
while (lst)
{
if (find == lst->content)
return (lst);
lst = lst->next;
}
return (NULL);
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: user42 <user42@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/12 15:51:15 by smaccary #+# #+# */
/* Updated: 2020/07/10 23:06:47 by user42 ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
#include <stdlib.h>
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *next;
if (!lst || !*lst)
return ;
next = (*lst)->next;
while (next)
{
next = (*lst)->next;
ft_lstdelone(*lst, del);
*lst = next;
}
*lst = NULL;
}

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/12 17:14:00 by smaccary #+# #+# */
/* Updated: 2019/11/14 15:48:47 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
#include <stdlib.h>
t_list *ft_lstcpy(t_list *lst, void (*del)(void *))
{
t_list *dst;
t_list *dst_next;
if (!(dst = ft_lstnew(lst->content)))
return (NULL);
dst_next = dst;
while (lst->next)
{
if (!(dst_next->next = ft_lstnew(lst->next->content)))
{
ft_lstclear(&dst, del);
return (NULL);
}
lst = lst->next;
dst_next = dst_next->next;
}
return (dst);
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/12 14:08:06 by smaccary #+# #+# */
/* Updated: 2019/11/17 16:50:42 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
#include <stdlib.h>
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (!del || !lst || !(lst->content))
return ;
(*del)(lst->content);
free(lst);
}

View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/12 17:01:45 by smaccary #+# #+# */
/* Updated: 2019/11/17 16:56:37 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
#include <stdlib.h>
void ft_lstiter(t_list *lst, void (*f)(void *))
{
while (lst && f)
{
(*f)(lst->content);
lst = lst->next;
}
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/11 16:47:04 by smaccary #+# #+# */
/* Updated: 2019/11/11 16:50:06 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
t_list *ft_lstlast(t_list *lst)
{
if (lst == NULL)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}

View file

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <smaccary@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/12 17:09:26 by smaccary #+# #+# */
/* Updated: 2020/07/31 17:53:56 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *dst;
t_list *dst_next;
if (!*f || !lst || !(dst = ft_lstnew((*f)(lst->content))))
return (NULL);
dst_next = dst;
while (lst->next)
{
if (!(dst_next->next = ft_lstnew((*f)(lst->next->content))))
{
ft_lstclear(&dst, del);
return (NULL);
}
if (dst_next->next->content == NULL)
{
ft_lstclear(&dst, del);
return (NULL);
}
lst = lst->next;
dst_next = dst_next->next;
}
return (dst);
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/11 15:40:57 by smaccary #+# #+# */
/* Updated: 2019/11/16 18:53:06 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
t_list *ft_lstnew(void *content)
{
t_list *dst;
dst = malloc(sizeof(t_list));
if (!dst)
return (NULL);
dst->content = content;
dst->next = NULL;
return (dst);
}

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/11 16:39:19 by smaccary #+# #+# */
/* Updated: 2019/11/12 17:06:47 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#include "linked_lists.h"
int ft_lstsize(t_list *lst)
{
int len;
len = 0;
while (lst)
{
lst = lst->next;
len++;
}
return (len);
}

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* linked_lists.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smaccary <smaccary@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/31 17:51:32 by smaccary #+# #+# */
/* Updated: 2020/07/31 17:51:32 by smaccary ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LINKED_LISTS_H
# define LINKED_LISTS_H
# include <stdlib.h>
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
void ft_lstadd_back(t_list **alst, t_list *new);
void ft_lstadd_front(t_list **alst, t_list *new);
t_list *ft_lstchr(t_list *lst, void *find);
void ft_lstclear(t_list **lst, void (*del)(void *));
t_list *ft_lstcpy(t_list *lst, void (*del)(void *));
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstlast(t_list *lst);
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
t_list *ft_lstnew(void *content);
int ft_lstsize(t_list *lst);
#endif