연결리스트에 있는 총 노드의 수(연결리스트의 길이)를 반환해주는 함수
int ft_lstsize(t_list *lst)
🔩 parameters
*lst - 길이를 구할 연결리스트
📬 return
int형 반환
- 연결리스트에 있는 총 노드의 수(연결리스트의 길이)를 반환
t_list의 next를 사용해 더이상 다음 노드(*lst == NULL)가 없을때까지 진행하며 길이를 확인
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int count;
t_list *testnode;
count = 0;
testnode = lst;
while (testnode != NULL)
{
testnode = testnode->next;
count++;
}
return (count);
}