change fonctions pour list avec nouvelles fonctions pour listes a deux sens

This commit is contained in:
hugogogo
2022-03-24 16:49:59 +01:00
parent bc53060626
commit 60af4e44b0
27 changed files with 484 additions and 13 deletions

41
srcs/ft_lstpush_back.c Normal file
View 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);
}