remis les header des toutes les fonctions
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
|
||||
#include <libc.h>
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
char *ptr;
|
||||
char *ptr2;
|
||||
|
||||
ptr = (char *)dst;
|
||||
ptr2 = (char *)src;
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
ptr[i] = ptr2[i];
|
||||
return (dst);
|
||||
}
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *lst;
|
||||
|
||||
if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
return (NULL);
|
||||
if (!content)
|
||||
lst->content = NULL;
|
||||
else
|
||||
{
|
||||
if (!(lst->content = malloc(sizeof(content))))
|
||||
return (NULL);
|
||||
ft_memcpy(lst->content, content, sizeof(content));
|
||||
}
|
||||
lst->next = NULL;
|
||||
return (lst);
|
||||
}
|
||||
|
||||
void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (alst)
|
||||
{
|
||||
tmp = *alst;
|
||||
if (!tmp)
|
||||
*alst = new;
|
||||
else
|
||||
{
|
||||
while (tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = new;
|
||||
}
|
||||
new->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//##############################################################################
|
||||
|
||||
void ft_delete(void *element)
|
||||
{
|
||||
*(char*)element = '\0';
|
||||
}
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
|
||||
int main(void)
|
||||
{
|
||||
t_list *toto;
|
||||
void (ft_delete)(void*);
|
||||
|
||||
toto = ft_lstnew("a");
|
||||
toto->next = ft_lstnew("b");
|
||||
toto->next->next = ft_lstnew("c");
|
||||
printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
ft_lstdelone(toto->next, ft_delete);
|
||||
printf("----------------------\n");
|
||||
printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
lst = NULL;
|
||||
}
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:11:53 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:11:57 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** add an element to the end of a list
|
||||
** or first if list has no element so far
|
||||
@@ -12,20 +24,6 @@
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
@@ -35,11 +33,7 @@
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** {
|
||||
** if (!(lst->content = malloc(sizeof(content))))
|
||||
** return (NULL);
|
||||
** ft_memcpy(lst->content, content, sizeof(content));
|
||||
** }
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:12:02 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:13:14 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** add an element to the begining of a list
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:13:30 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:13:49 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** delete and free an element of the list and all the followings
|
||||
*/
|
||||
@@ -11,20 +23,6 @@
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
@@ -102,4 +100,3 @@ void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
ft_lstclear(&(*lst)->next, del);
|
||||
ft_lstdelone(*lst, del);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:03 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:14:05 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** free an element and delete its content with del
|
||||
** next is not free
|
||||
@@ -12,20 +24,6 @@
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:14:29 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** go through all elements of the list and apply the function f to each of them
|
||||
*/
|
||||
@@ -11,20 +23,6 @@
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
@@ -34,11 +32,7 @@
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** {
|
||||
** if (!(lst->content = malloc(sizeof(content))))
|
||||
** return (NULL);
|
||||
** ft_memcpy(lst->content, content, sizeof(content));
|
||||
** }
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:49 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:15:36 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return a pointer to the last element of a list
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:15:42 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:16:15 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** iterate trhough linked list and apply to each element a function f
|
||||
** if necessary the function del is used to delete an element
|
||||
@@ -12,20 +24,6 @@
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
@@ -35,11 +33,7 @@
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** {
|
||||
** if (!(lst->content = malloc(sizeof(content))))
|
||||
** return (NULL);
|
||||
** ft_memcpy(lst->content, content, sizeof(content));
|
||||
** }
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:16:20 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:16:30 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new list
|
||||
*/
|
||||
@@ -5,20 +17,6 @@
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
|
||||
@@ -7,20 +7,6 @@
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
@@ -30,11 +16,7 @@
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** {
|
||||
** if (!(lst->content = malloc(sizeof(content))))
|
||||
** return (NULL);
|
||||
** ft_memcpy(lst->content, content, sizeof(content));
|
||||
** }
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
|
||||
Reference in New Issue
Block a user