2024-10-21 11:50:55 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* ft_lstsize_bonus.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2024/10/21 11:44:46 by kcolin #+# #+# */
|
|
|
|
|
/* Updated: 2024/10/21 11:48:35 by kcolin ### ########.fr */
|
|
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "libft.h"
|
|
|
|
|
|
2024-10-21 12:16:09 +02:00
|
|
|
int ft_lstsize(t_list *lst)
|
2024-10-21 11:50:55 +02:00
|
|
|
{
|
|
|
|
|
t_list *current;
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
current = lst;
|
|
|
|
|
while (current != NULL)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
current = current->next;
|
|
|
|
|
}
|
|
|
|
|
return (count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
t_list *list;
|
|
|
|
|
t_list *new;
|
|
|
|
|
|
|
|
|
|
list = ft_lstnew("Hello There!");
|
|
|
|
|
printf("current:\t%p\n", list);
|
|
|
|
|
printf("content:\t%s\n", (char *)list->content);
|
|
|
|
|
printf("next:\t\t%p\n", list->next);
|
|
|
|
|
printf("length:\t%d\n", ft_lstsize(list));
|
|
|
|
|
new = ft_lstnew("New Element!");
|
|
|
|
|
ft_lstadd_front(&list, new);
|
|
|
|
|
printf("current:\t%p\n", list);
|
|
|
|
|
printf("content:\t%s\n", (char *)list->content);
|
|
|
|
|
printf("next:\t\t%p\n", list->next);
|
|
|
|
|
printf("length:\t%d\n", ft_lstsize(list));
|
|
|
|
|
free(list->next);
|
|
|
|
|
free(list);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
*/
|