링크드 리스트의 맨 앞에 요소를 추가함
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
void ft_lstadd_front(t_list **lst, t_list *new);
void
없음
new
요소를 추가한다.테스트
t_list **list;
ft_lstadd_front(list, ft_lstnew(1));
ft_lstadd_front(list, ft_lstnew(2));
ft_lstadd_front(list, ft_lstnew(3));
t_list *tmp;
tmp = (*list);
while(tmp != NULL)
{
printf("[%p] data : %d, next : %p\n",tmp, tmp->content, tmp->next );
tmp = tmp->next;
}
출력
/Users/mjung/mjung/GIT_HUB/Libft/cmake-build-debug/Libft
[0x7f844c400690] data : 3, next : 0x7f844c400630
[0x7f844c400630] data : 2, next : 0x7f844c400620
[0x7f844c400620] data : 1, next : 0x0