/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstlast_bonus.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: thrieg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/16 12:21:13 by thrieg #+# #+# */ /* Updated: 2025/02/16 19:04:00 by thrieg ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" //returns NULL if lst is NULL t_list *ft_lstlast(t_list *lst) { if (!lst) return (NULL); while (lst->next) lst = lst->next; return (lst); } /* * @return the element of `lst` at position `i`, NULL if doesn't exist. * `ft_lstat(lst, 0)` returns `lst`. */ t_list *ft_lstat(t_list *lst, size_t i) { size_t j; if (lst == NULL) return (lst); j = 0; while (lst->next != NULL && j < i) { lst = lst->next; j++; } if (j != i) return (NULL); return (lst); }