-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstsize.c
executable file
·48 lines (44 loc) · 1.68 KB
/
ft_lstsize.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssoeno <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/21 10:36:09 by ssoeno #+# #+# */
/* Updated: 2024/04/22 17:13:23 by ssoeno ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int count;
t_list *current_node;
count = 0;
current_node = lst;
while (current_node != NULL)
{
count++;
current_node = current_node->next;
}
return (count);
}
// int main() {
// t_list *head = NULL;
// printf("Test Empty List: Expected 0, Got %d\n", ft_lstsize(head));
// // Add one node
// head = ft_lstnew("Hello, World!");
// printf("Test Single Node List: Expected 1, Got %d\n", ft_lstsize(head));
// // Add more nodes
// head->next = ft_lstnew("Node 2");
// head->next->next = ft_lstnew("Node 3");
// printf("Test Three Nodes List: Expected 3, Got %d\n", ft_lstsize(head));
// // Free memory
// t_list *current = head;
// while (current != NULL) {
// t_list *temp = current;
// current = current->next;
// free(temp);
// }
// return 0;
// }