Merge branch 'master' of bitbucket.org:hugogogo/libft
This commit is contained in:
95
Makefile
95
Makefile
@@ -14,14 +14,6 @@ DEPS = $(_DEP:%.h=$(IDIR)/%.h)
|
||||
CFLAGS = -I$(IDIR)
|
||||
CFLAGS += -Wall -Wextra -Werror -g3
|
||||
|
||||
# ft_putstr
|
||||
# ft_atoi
|
||||
# ft_putchar
|
||||
# ft_putnbrendl
|
||||
# ft_putnbrendl_fd
|
||||
# ft_putchar_fd
|
||||
# ft_putnbr_fd
|
||||
|
||||
SRCS = ft_memset.c \
|
||||
ft_bzero.c \
|
||||
ft_memcpy.c \
|
||||
@@ -29,7 +21,10 @@ SRCS = ft_memset.c \
|
||||
ft_memmove.c \
|
||||
ft_memchr.c \
|
||||
ft_memcmp.c \
|
||||
ft_strlen.c \
|
||||
ft_memalloc.c \
|
||||
ft_memdel.c \
|
||||
ft_calloc.c \
|
||||
\
|
||||
ft_isalpha.c \
|
||||
ft_isdigit.c \
|
||||
ft_isalnum.c \
|
||||
@@ -38,6 +33,8 @@ SRCS = ft_memset.c \
|
||||
ft_isprint.c \
|
||||
ft_toupper.c \
|
||||
ft_tolower.c \
|
||||
\
|
||||
ft_strlen.c \
|
||||
ft_strchr.c \
|
||||
ft_strrchr.c \
|
||||
ft_strchrset.c \
|
||||
@@ -45,33 +42,10 @@ SRCS = ft_memset.c \
|
||||
ft_strlcpy.c \
|
||||
ft_strlcat.c \
|
||||
ft_strnstr.c \
|
||||
ft_atoi.c \
|
||||
ft_atol.c \
|
||||
ft_calloc.c \
|
||||
ft_strdup.c \
|
||||
\
|
||||
ft_substr.c \
|
||||
ft_strjoin.c \
|
||||
ft_strtrim.c \
|
||||
ft_split.c \
|
||||
ft_itoa.c \
|
||||
ft_utoa.c \
|
||||
ft_strmapi.c \
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
\
|
||||
ft_lstnew.c \
|
||||
ft_lstadd_front.c \
|
||||
ft_lstsize.c \
|
||||
ft_lstlast.c \
|
||||
ft_lstadd_back.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstclear.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
\
|
||||
ft_strcat.c \
|
||||
ft_strcmp.c \
|
||||
ft_strcpy.c \
|
||||
@@ -87,15 +61,33 @@ SRCS = ft_memset.c \
|
||||
ft_strmap.c \
|
||||
ft_strnequ.c \
|
||||
ft_strnew.c \
|
||||
ft_memalloc.c \
|
||||
ft_memdel.c \
|
||||
ft_putchar.c \
|
||||
ft_putendl.c \
|
||||
ft_putnbr.c \
|
||||
ft_putnbrendl.c \
|
||||
ft_putnbrendl_fd.c \
|
||||
ft_substr.c \
|
||||
ft_split.c \
|
||||
\
|
||||
ft_atoi.c \
|
||||
ft_atol.c \
|
||||
ft_itoa.c \
|
||||
ft_utoa.c \
|
||||
\
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
ft_putnbrbase.c \
|
||||
ft_putstr.c \
|
||||
\
|
||||
ft_lstcreate.c \
|
||||
ft_lstpush_back.c \
|
||||
ft_lstpush_front.c \
|
||||
ft_lstloop.c \
|
||||
ft_lstloop_back.c \
|
||||
ft_lstbegin.c \
|
||||
ft_lstend.c \
|
||||
ft_lstfind.c \
|
||||
ft_lstinsert.c \
|
||||
ft_lsterase.c \
|
||||
ft_lstfree.c \
|
||||
ft_lstlen.c \
|
||||
ft_lstcopy.c \
|
||||
\
|
||||
ft_any.c \
|
||||
ft_atoibase.c \
|
||||
ft_convertbase.c \
|
||||
@@ -118,7 +110,28 @@ SRCS = ft_memset.c \
|
||||
ft_smaller.c \
|
||||
ft_sign.c \
|
||||
ft_sqrt.c \
|
||||
ft_free_tab.c
|
||||
ft_free_tab.c \
|
||||
\
|
||||
ft_arrint.c
|
||||
|
||||
# deleted : \
|
||||
ft_lstnew.c \
|
||||
ft_lstadd_front.c \
|
||||
ft_lstsize.c \
|
||||
ft_lstlast.c \
|
||||
ft_lstadd_back.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstclear.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
\
|
||||
ft_putstr.c \
|
||||
ft_putchar.c \
|
||||
ft_putendl.c \
|
||||
ft_putnbr.c \
|
||||
ft_putnbrendl.c \
|
||||
ft_putnbrendl_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
|
||||
|
||||
ODIR = ./builds
|
||||
|
||||
24
deleted/ft_lst_find.bak
Normal file
24
deleted/ft_lst_find.bak
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstfind.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/23 22:48:47 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/23 22:49:16 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* find an element with the comp function, and return a pointer to it
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *))
|
||||
{
|
||||
while (lst && (!comp(to_find, lst->content)))
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
@@ -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,11 +48,9 @@ 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->next = NULL;
|
||||
return (lst);
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:45:53 by hulamy #+# #+# */
|
||||
/* Updated: 2020/02/27 18:06:10 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/04/21 19:31:18 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -52,26 +52,53 @@ char **ft_split(char const *s, char c);
|
||||
char *ft_itoa(long int n);
|
||||
char *ft_utoa(unsigned long int n);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
void ft_putnbrbase(int nbr, char *base);
|
||||
|
||||
/*
|
||||
void ft_putchar(char c);
|
||||
void ft_putendl(char const *str);
|
||||
void ft_putnbr(int nbr);
|
||||
void ft_putstr(char const *str);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
*/
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *prev;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
/*
|
||||
t_list *ft_lstnew(void *content);
|
||||
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);
|
||||
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_lstclear(t_list **lst, void (*del)(void *));
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
t_list *ft_lstmap(t_list *l, void *(*f)(void*), void (*d)(void*));
|
||||
*/
|
||||
//void ft_lstremove(t_list *lst, void (*del)(void *));
|
||||
//t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *));
|
||||
t_list *ft_lstcreate(void *content);
|
||||
void *ft_lstpush_back(t_list **lst, t_list *new);
|
||||
void ft_lstpush_front(t_list **alst, t_list *new);
|
||||
void ft_lstloop(t_list *lst, void (*f)(void *));
|
||||
void ft_lstloop_back(t_list *lst, void (*f)(void *));
|
||||
t_list *ft_lstbegin(t_list *lst);
|
||||
t_list *ft_lstend(t_list *lst);
|
||||
t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *));
|
||||
void ft_lstinsert(t_list *lst, t_list *new);
|
||||
void ft_lsterase(t_list *lst, void (*del)(void *));
|
||||
void ft_lstfree(t_list *lst, void (*del)(void *));
|
||||
int ft_lstlen(t_list *lst);
|
||||
t_list *ft_lstcopy(t_list *lst, void *(*cpy)(void *));
|
||||
|
||||
char *ft_strcat(char *s1, const char *s2);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
@@ -90,11 +117,6 @@ int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strnew(size_t size);
|
||||
void *ft_memalloc(size_t size);
|
||||
void ft_memdel(void **ap);
|
||||
void ft_putchar(char c);
|
||||
void ft_putendl(char const *str);
|
||||
void ft_putnbr(int nbr);
|
||||
void ft_putstr(char const *str);
|
||||
void ft_putnbrbase(int nbr, char *base);
|
||||
int ft_atoibase(char *str, char *base);
|
||||
char *ft_convertbase(char *nbr, char *base_from, char *base_to);
|
||||
char *ft_convertbase_free(char *nbr, char *b_from, char *b_to);
|
||||
@@ -113,4 +135,6 @@ int ft_sign(int i);
|
||||
int ft_sqrt(int i);
|
||||
void ft_free_tab(char **tab);
|
||||
|
||||
int ft_arrint(int * intarr, int comp, size_t size);
|
||||
|
||||
#endif
|
||||
|
||||
31
srcs/ft_arrint.c
Normal file
31
srcs/ft_arrint.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_arrint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/21 19:30:25 by simplonco #+# #+# */
|
||||
/* Updated: 2022/04/21 19:30:35 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* search through an arr of int if it contains the int comp
|
||||
* return 0 if found, 1 otherwise
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_arrint(int * intarr, int comp, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!intarr)
|
||||
return 1;
|
||||
i = -1;
|
||||
while (++i < size)
|
||||
if (intarr[i] == comp)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
25
srcs/ft_lstbegin.c
Normal file
25
srcs/ft_lstbegin.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstbegin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 15:05:21 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 15:10:45 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* return a pointer to the first element of a two-way list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstbegin(t_list *lst)
|
||||
{
|
||||
while (lst->prev)
|
||||
lst = lst->prev;
|
||||
return (lst);
|
||||
}
|
||||
|
||||
34
srcs/ft_lstcopy.c
Normal file
34
srcs/ft_lstcopy.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstcopy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 16:26:27 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 16:37:39 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* copy a two-way list with the copy function for the content
|
||||
* and return pointer to the begining of the new list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstcopy(t_list *lst, void *(*cpy)(void *))
|
||||
{
|
||||
t_list *lst_copy;
|
||||
|
||||
if (!lst || !cpy)
|
||||
return (NULL);
|
||||
lst_copy = NULL;
|
||||
while (lst)
|
||||
{
|
||||
ft_lstpush_back(&lst_copy, ft_lstcreate(cpy(lst->content)));
|
||||
lst = lst->next;
|
||||
}
|
||||
return (ft_lstbegin(lst_copy));
|
||||
}
|
||||
|
||||
31
srcs/ft_lstcreate.c
Normal file
31
srcs/ft_lstcreate.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstcreate.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 13:12:50 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 14:29:04 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* create a new two-way list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstcreate(void *content)
|
||||
{
|
||||
t_list *lst;
|
||||
|
||||
lst = (t_list *)malloc(sizeof(*lst));
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
lst->content = content;
|
||||
lst->prev = NULL;
|
||||
lst->next = NULL;
|
||||
return (lst);
|
||||
}
|
||||
|
||||
24
srcs/ft_lstend.c
Normal file
24
srcs/ft_lstend.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstend.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 15:11:41 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 15:12:17 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* return a pointer to the last element of a two-way list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstend(t_list *lst)
|
||||
{
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
32
srcs/ft_lsterase.c
Normal file
32
srcs/ft_lsterase.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lsterase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 15:31:16 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 20:54:20 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* erase an element in two-way list
|
||||
* and rejoin the list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lsterase(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->content);
|
||||
if (lst->prev)
|
||||
lst->prev->next = lst->next;
|
||||
if (lst->next)
|
||||
lst->next->prev = lst->prev;
|
||||
free(lst);
|
||||
lst = NULL;
|
||||
}
|
||||
|
||||
25
srcs/ft_lstfind.c
Normal file
25
srcs/ft_lstfind.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstfind.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/23 22:48:47 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 15:23:22 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* find an element in two-way list with the comp function
|
||||
* return a pointer to it
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *))
|
||||
{
|
||||
while (lst && (!comp(to_find, lst->content)))
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
33
srcs/ft_lstfree.c
Normal file
33
srcs/ft_lstfree.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstfree.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 15:49:35 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 16:16:47 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* delete and free an element of a two-way list and all the followings
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstfree(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
t_list *next;
|
||||
|
||||
if (lst && lst->prev)
|
||||
lst->prev->next = NULL;
|
||||
while (lst != NULL)
|
||||
{
|
||||
next = lst->next;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
lst = next;
|
||||
}
|
||||
}
|
||||
|
||||
27
srcs/ft_lstinsert.c
Normal file
27
srcs/ft_lstinsert.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstinsert.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 15:22:46 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 15:31:52 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* insert an element in two-way list just after the one in parameter
|
||||
* and rejoin the list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstinsert(t_list *lst, t_list *new)
|
||||
{
|
||||
new->next = lst->next;
|
||||
lst->next = new;
|
||||
new->next->prev = new;
|
||||
new->prev = lst;
|
||||
}
|
||||
|
||||
30
srcs/ft_lstlen.c
Normal file
30
srcs/ft_lstlen.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 16:20:25 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 16:22:24 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* return the len of the two-way list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstlen(t_list *lst)
|
||||
{
|
||||
int size;
|
||||
|
||||
size = 0;
|
||||
while (lst)
|
||||
{
|
||||
size++;
|
||||
lst = lst->next;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
30
srcs/ft_lstloop.c
Normal file
30
srcs/ft_lstloop.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstloop.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 14:37:15 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 14:38:32 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* go forward through all elements of a two-way list
|
||||
* and apply the function f to each of them
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstloop(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!f)
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
|
||||
30
srcs/ft_lstloop_back.c
Normal file
30
srcs/ft_lstloop_back.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstloop_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 15:01:37 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 15:02:02 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* go backward through all elements of a two-way list
|
||||
* and apply the function f to each of them
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstloop_back(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!f)
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->prev;
|
||||
}
|
||||
}
|
||||
|
||||
41
srcs/ft_lstpush_back.c
Normal file
41
srcs/ft_lstpush_back.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstpush_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 13:37:11 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 14:28:49 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* add an element to the end of a two-way list, or first if list has no element
|
||||
* return NULL if element is NULL (eg it returned from ft_lstcreate and failed)
|
||||
* or else address to the element added
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_lstpush_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (!new)
|
||||
return (NULL);
|
||||
if (lst)
|
||||
{
|
||||
tmp = *lst;
|
||||
if (!tmp)
|
||||
*lst = new;
|
||||
else
|
||||
{
|
||||
while (tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = new;
|
||||
new->prev = tmp;
|
||||
}
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
24
srcs/ft_lstpush_front.c
Normal file
24
srcs/ft_lstpush_front.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstpush_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/24 14:25:25 by simplonco #+# #+# */
|
||||
/* Updated: 2022/03/24 14:32:14 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
* add an element to the begining of a two-way list
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstpush_front(t_list **alst, t_list *new)
|
||||
{
|
||||
new->next = *alst;
|
||||
(*alst)->prev = new;
|
||||
*alst = new;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:17:00 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:23:43 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/03/24 17:01:57 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -47,13 +47,13 @@ void ft_putnbrbase(int nbr, char *base)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
ft_putchar('-');
|
||||
ft_putchar_fd('-', 1);
|
||||
n = -n;
|
||||
}
|
||||
while (base[i])
|
||||
i++;
|
||||
if (n >= i)
|
||||
ft_putnbrbase(n / i, base);
|
||||
ft_putchar(base[n % i]);
|
||||
ft_putchar_fd(base[n % i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user