copy on git
This commit is contained in:
commit
42653de246
205 changed files with 7459 additions and 0 deletions
44
libft/ft_lstlast_bonus.c
Executable file
44
libft/ft_lstlast_bonus.c
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue