[ft_lstadd_front] note

duckkuri·2020년 10월 16일
0

42Seoul_Libft_Story

목록 보기
13/22

[list][function] ft_lstadd_front

링크드 리스트의 맨 앞에 요소를 추가함

t_list 구조체

typedef struct s_list
{
  void *content;
  struct s_list *next;
}	t_list;

type

void ft_lstadd_front(t_list **lst, t_list *new);

매개변수

  • 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
profile
😤 Today I Learned

0개의 댓글