-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstlast.c
executable file
·49 lines (46 loc) · 1.62 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssoeno <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/21 10:35:26 by ssoeno #+# #+# */
/* Updated: 2024/04/22 20:13:03 by ssoeno ### ########.fr */
/* */
/* ************************************************************************** */
#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() {
// t_list *head = NULL;
// t_list *last;
// int *p1 = malloc(sizeof(int));
// int *p2 = malloc(sizeof(int));
// int *p3 = malloc(sizeof(int));
// if(p1 == NULL || p2 == NULL || p3 == NULL){
// return -1;
// }
// *p1 = 42;
// *p2 = 43;
// *p3 = 44;
// head = ft_lstnew(p1);
// head->next = ft_lstnew(p2);
// head->next->next = ft_lstnew(p3);
// last = ft_lstlast(head);
// if (last != NULL && last->content == p3)
// printf("Last content is 44.\n");
// // clean lists
// while (head != NULL) {
// t_list *tmp = head;
// head = head->next;
// free(tmp);
// }
// return 0;
// }