narnaud
3 years ago
36 changed files with 371 additions and 157 deletions
@ -0,0 +1,27 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_add.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/24 10:46:25 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/25 14:15:13 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
t_dlist *ft_dlst_add(t_dlist *prev, void *content) |
|||
{ |
|||
t_dlist *new; |
|||
|
|||
if (!content) |
|||
return (prev); |
|||
new = ft_calloc(1, sizeof(t_dlist)); |
|||
if (prev) |
|||
prev->next = new; |
|||
new->previous = prev; |
|||
new->content = content; |
|||
return (new); |
|||
} |
@ -0,0 +1,20 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_dlst_n.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/24 10:51:20 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 11:27:40 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
t_dlist *ft_dlst_n(t_dlist *lst, size_t n) |
|||
{ |
|||
while (n-- && lst) |
|||
lst = lst->next; |
|||
return (lst); |
|||
} |
@ -0,0 +1,41 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_dlst_to_arr.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/24 10:50:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 11:33:57 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
char **ft_dlst_to_arr(t_dlist *ptr) |
|||
{ |
|||
char **ret; |
|||
t_dlist *last; |
|||
t_dlist *tmp; |
|||
size_t count; |
|||
|
|||
last = ptr; |
|||
count = 1; |
|||
if (!ptr) |
|||
return (ft_calloc(1, sizeof(char *))); |
|||
while (ptr->previous) |
|||
{ |
|||
ptr = ptr->previous; |
|||
count++; |
|||
} |
|||
ret = ft_calloc(count + 1, sizeof(char *)); |
|||
ret[count] = NULL; |
|||
while (count--) |
|||
{ |
|||
ret[count] = last->content; |
|||
tmp = last; |
|||
free(last); |
|||
last = tmp->previous; |
|||
} |
|||
return (ret); |
|||
} |
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_first.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/25 09:06:44 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/25 13:26:04 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
size_t ft_ilst_first(t_i_slist *lst, int (*fct)(int a, int b)) |
|||
{ |
|||
int previous; |
|||
size_t i; |
|||
|
|||
i = 1; |
|||
if (!lst) |
|||
return (0); |
|||
while (lst) |
|||
{ |
|||
previous = lst->nb; |
|||
lst = lst->next; |
|||
if (lst && fct(previous, lst->nb)) |
|||
return (i); |
|||
i++; |
|||
} |
|||
return (-1); |
|||
} |
@ -0,0 +1,25 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_free.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/25 09:27:41 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/25 14:18:37 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
void ft_ilst_free(t_i_slist *list) |
|||
{ |
|||
t_i_slist *next; |
|||
|
|||
while (list) |
|||
{ |
|||
next = list->next; |
|||
free(list); |
|||
list = next; |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_is_in.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/25 13:22:49 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/25 14:19:02 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
int ft_ilst_is_in(int value, t_i_slist lst) |
|||
{ |
|||
if (lst.nb == value && lst.next) |
|||
return (1); |
|||
while (lst.next) |
|||
{ |
|||
if (lst.nb == value) |
|||
return (1); |
|||
else |
|||
lst = *(lst.next); |
|||
} |
|||
return (0); |
|||
} |
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_free_split.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/25 08:55:20 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/25 08:57:26 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
void ft_free_split(char **split) |
|||
{ |
|||
int i; |
|||
|
|||
i = 0; |
|||
while (split[i]) |
|||
{ |
|||
free(split[i]); |
|||
i++; |
|||
} |
|||
free(split); |
|||
} |
@ -0,0 +1,18 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_croissant.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/25 09:14:45 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/25 09:15:32 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
int ft_croissant(int a, int b) |
|||
{ |
|||
return (a <= b); |
|||
} |
@ -0,0 +1,18 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_decroissant.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/03/25 09:14:45 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/25 10:53:14 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
int ft_decroissant(int a, int b) |
|||
{ |
|||
return (a > b); |
|||
} |
@ -1,26 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstadd_back_bonus.c :+: :+: :+: */ |
|||
/* ft_lstadd_back.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:51:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
void ft_lstadd_back(t_list **alst, t_list *new) |
|||
void ft_slst_add_back(t_slist **alst, t_slist *new) |
|||
{ |
|||
t_list *i_cell; |
|||
t_slist *i_cell; |
|||
|
|||
if (!alst || !new) |
|||
return ; |
|||
if (*alst) |
|||
{ |
|||
i_cell = ft_lstlast(*alst); |
|||
i_cell = ft_slst_last(*alst); |
|||
i_cell->next = new; |
|||
} |
|||
else |
@ -1,18 +1,18 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstadd_front_bonus.c :+: :+: :+: */ |
|||
/* ft_lstadd_front.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:48:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
void ft_lstadd_front(t_list **alst, t_list *new) |
|||
void ft_slst_add_front(t_slist **alst, t_slist *new) |
|||
{ |
|||
if (!alst || !new) |
|||
return ; |
@ -1,27 +1,27 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstclear_bonus.c :+: :+: :+: */ |
|||
/* ft_lstclear.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:53:04 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
void ft_lstclear(t_list **lst, void (*del)(void *)) |
|||
void ft_slst_clear(t_slist **lst, void (*del)(void *)) |
|||
{ |
|||
t_list *next_cell; |
|||
t_slist *next_cell; |
|||
|
|||
if (!del) |
|||
return ; |
|||
while (lst && *lst) |
|||
{ |
|||
next_cell = (*lst)->next; |
|||
ft_lstdelone(*lst, del); |
|||
ft_slst_delone(*lst, del); |
|||
*lst = next_cell; |
|||
} |
|||
} |
@ -1,18 +1,18 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstdelone_bonus.c :+: :+: :+: */ |
|||
/* ft_lstdelone.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:51:53 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
void ft_lstdelone(t_list *lst, void (*del)(void *)) |
|||
void ft_slst_delone(t_slist *lst, void (*del)(void *)) |
|||
{ |
|||
if (!lst || !del) |
|||
return ; |
@ -1,22 +1,22 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstiter_bonus.c :+: :+: :+: */ |
|||
/* ft_lstiter.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:54:03 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
void ft_lstiter(t_list *lst, void (*f)(void *)) |
|||
void ft_slst_iter(t_slist *lst, void (*f)(void *)) |
|||
{ |
|||
if (!lst || !f) |
|||
return ; |
|||
(*f)(lst->content); |
|||
if (lst->next) |
|||
ft_lstiter(lst->next, f); |
|||
ft_slst_iter(lst->next, f); |
|||
} |
@ -1,18 +1,18 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstlast_bonus.c :+: :+: :+: */ |
|||
/* ft_lstlast.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:50:21 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
t_list *ft_lstlast(t_list *lst) |
|||
t_slist *ft_slst_last(t_slist *lst) |
|||
{ |
|||
if (!lst) |
|||
return (NULL); |
@ -1,29 +1,29 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstmap_bonus.c :+: :+: :+: */ |
|||
/* ft_lstmap.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:54:31 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) |
|||
t_slist *ft_slst_map(t_slist *lst, void *(*f)(void *), void (*del)(void *)) |
|||
{ |
|||
t_list *new_lst; |
|||
t_slist *new_lst; |
|||
|
|||
if (!lst || !f) |
|||
return (NULL); |
|||
new_lst = ft_lstnew((*f)(lst->content)); |
|||
new_lst = ft_slst_new((*f)(lst->content)); |
|||
if (!new_lst) |
|||
{ |
|||
ft_lstclear(&new_lst, del); |
|||
ft_slst_clear(&new_lst, del); |
|||
return (NULL); |
|||
} |
|||
new_lst->next = ft_lstmap(lst->next, f, del); |
|||
new_lst->next = ft_slst_map(lst->next, f, del); |
|||
return (new_lst); |
|||
} |
@ -1,22 +1,22 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstnew_bonus.c :+: :+: :+: */ |
|||
/* ft_lstnew.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/20 17:36:09 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
t_list *ft_lstnew(void *content) |
|||
t_slist *ft_slst_new(void *content) |
|||
{ |
|||
t_list *i_cell; |
|||
t_slist *i_cell; |
|||
|
|||
i_cell = (t_list *)malloc(sizeof(*i_cell)); |
|||
i_cell = (t_slist *)malloc(sizeof(*i_cell)); |
|||
if (!i_cell) |
|||
return (NULL); |
|||
i_cell->content = content; |
@ -1,18 +1,18 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_lstsize_bonus.c :+: :+: :+: */ |
|||
/* ft_lstsize.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/22 14:49:32 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
int ft_lstsize(t_list *lst) |
|||
int ft_slst_size(t_slist *lst) |
|||
{ |
|||
size_t lst_size; |
|||
|
@ -1,25 +1,33 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ft_strlen.c :+: :+: :+: */ |
|||
/* ft_len.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2021/10/18 16:04:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ |
|||
/* Updated: 2022/03/25 11:57:59 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "../libft.h" |
|||
|
|||
size_t ft_strlen(const char *s) |
|||
size_t ft_strlen_to(const char *str, char ch) |
|||
{ |
|||
size_t i; |
|||
|
|||
i = 0; |
|||
while (s[i] != '\0') |
|||
{ |
|||
while (str[i] && str[i] != ch) |
|||
i++; |
|||
return (i); |
|||
} |
|||
|
|||
size_t ft_strlen(const char *str) |
|||
{ |
|||
size_t i; |
|||
|
|||
i = 0; |
|||
while (str[i] != '\0') |
|||
i++; |
|||
} |
|||
return (i); |
|||
} |
Loading…
Reference in new issue