-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstlast_bonus.c
33 lines (31 loc) · 1.32 KB
/
ft_lstlast_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: flverge <flverge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 15:19:32 by flverge #+# #+# */
/* Updated: 2024/09/22 17:06:05 by flverge ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Returns the last element of the list.
*
* This function traverses the linked list until it finds the last element,
* which is then returned. If the list is empty, it returns NULL.
*
* @param lst The beginning of the list.
* @return The last element of the list, or NULL if the list is empty.
*/
t_list *ft_lstlast(t_list *lst)
{
while (lst)
{
if (!lst->next)
return (lst);
lst = lst->next;
}
return (lst);
}