-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstsize_bonus.c
52 lines (43 loc) · 1.58 KB
/
ft_lstsize_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ledias-d <[email protected]> #+# +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024-10-11 12:56:04 by ledias-d #+# #+# */
/* Updated: 2024-10-11 12:56:04 by ledias-d ### ########.rio */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
t_list *tmp;
i = 0;
tmp = lst;
while (tmp)
{
tmp = tmp->next;
i++;
}
return (i);
}
/*#include <stdio.h>
int main(void)
{
// Criando nós da lista
t_list *node1 = ft_lstnew("Node 1");
t_list *node2 = ft_lstnew("Node 2");
t_list *node3 = ft_lstnew("Node 3");
// Conectando os nós
node1->next = node2;
node2->next = node3;
// Teste: Calculando o tamanho da lista
int size = ft_lstsize(node1);
printf("Tamanho da lista: %d\n", size); // Saída esperada: 3
// Teste: Tamanho de lista vazia
size = ft_lstsize(NULL);
printf("Tamanho da lista vazia: %d\n", size); // Saída esperada: 0
return (0);
}*/