-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstlast.c
52 lines (40 loc) · 1.66 KB
/
ft_lstlast.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbrito-p <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/08 20:26:13 by mbrito-p #+# #+# */
/* Updated: 2023/05/08 20:26:13 by mbrito-p ### ########.fr */
/* */
/* ************************************************************************** */
// Returns the last node of the list.
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
if (!lst)
return (NULL);
while (lst->next != NULL)
{
lst = lst->next;
}
return lst;
}
// int main(void)
// {
// t_list *list = NULL;
// t_list *new_node;
// t_list *last;
// // Create the first node of the list
// list = ft_lstnew("Node 1");
// // Add a new node to the front of the list
// new_node = ft_lstnew("Node 2");
// ft_lstadd_front(&list, new_node);
// // Add another node to the front of the list
// new_node = ft_lstnew("Node 3");
// ft_lstadd_front(&list, new_node);
// last = ft_lstlast(list);
// printf("The last node of the list is: %s\n", (char *)last->content);
// return (0);
// }