lstadd_front ecrite avec main
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:10:33 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 13:58:54 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd(t_list **alst, t_list *new)
|
||||
{
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
||||
78
srcs/bonus/ft_lstadd_front.c
Normal file
78
srcs/bonus/ft_lstadd_front.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
** #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_front(t_list **alst, t_list *new);
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** char tresor;
|
||||
** char matos;
|
||||
** char friends;
|
||||
** t_list *toto;
|
||||
** t_list *tmp;
|
||||
**
|
||||
** tresor = 'a';
|
||||
** matos = 'b';
|
||||
** friends = 'c';
|
||||
** toto = ft_lstnew(&tresor);
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** tmp = ft_lstnew(&matos);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** tmp = ft_lstnew(&friends);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->dqta:%c\n",*(char*)(toto->next->next->content));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **alst, t_list *new)
|
||||
{
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
||||
@@ -1,15 +1,3 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:11:42 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/20 16:39:29 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new list
|
||||
*/
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/20 15:12:55 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/20 15:13:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user