-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstsize_bonus.c
74 lines (64 loc) · 2.06 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edetoh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/21 13:21:33 by edetoh #+# #+# */
/* Updated: 2024/10/25 11:13:44 by edetoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
ft_lstsize counts the number of elements in 'lst'.
Takes 'lst' (linked list).
Returns the number of elements in the list.
*/
int ft_lstsize(t_list *lst)
{
int result;
result = 0;
while (lst)
{
result++;
lst = lst->next;
}
return (result);
}
// #include <stdio.h>
// #include <stdlib.h>
// #include "libft.h"
// int main(void)
// {
// t_list *node;
// char *content = "Hello, world!";
// node = ft_lstnew(content);
// if (node)
// {
// printf("Node content: %s\n", (char *)node->content);
// printf("Node next: %p\n", (void *)node->next);
// t_list *newbuble1;
// char *newbuble1_content = "Coucou";
// // Allouer de la mémoire pour newbuble1
// newbuble1 = ft_lstnew(newbuble1_content);
// if (newbuble1)
// {
// ft_lstadd_front(&node, newbuble1);
// printf("Node content after add: %s\n", (char *)node->content);
// printf("Node next after add: %p\n", (void *)node->next);
// printf(">>>>> Taille : %i", ft_lstsize(newbuble1));
// }
// else
// {
// printf("Failed to create newbuble1\n");
// }
// }
// else
// {
// printf("Failed to create node\n");
// }
// // Libérer la mémoire allouée
// free(node);
// return 0;
// }