ft_lstnew - chanhl22/libft GitHub Wiki
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* ft_lstnew.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: chanhlee <[email protected].> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2021/01/29 10:57:19 by chanhlee #+# #+# */
9 /* Updated: 2021/01/29 15:28:59 by chanhlee ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12
13 #include "libft.h"
14
15 t_list *ft_lstnew(void *content)
16 {
17 t_list *node;
18
19 if (!(node = malloc(sizeof(t_list)))) //๋
ธ๋ ์์ฑ
20 return (NULL);
21 node->content = content; // ์์ฑ๋ ๋
ธ๋ ๋ค์์ ๋
ธ๋
22 node->next = NULL; // ๋ค์์ ๋
ธ๋๊ฐ ์์(NULL)
23 return (node);
24 }
์๋ก์ด ๊ตฌ์กฐ์ฒด๋ฅผ ์์ฑํ๊ณ , content ์ ์ ๋ ฅ ๋ฐ์ ์์๋ฅผ ๋ด์ ๋ฐํํด์ฃผ๋ ํจ์
- t_list ํฌ๊ธฐ๋ฅผ ๊ฐ์ง ์๋ก์ด ๊ตฌ์กฐ์ฒด๋ฅผ ์์ฑํ๊ณ , ์ ๋ ฅ ๋ฐ์ content ๋ฅผ ์์์ ๋ด์ ๋ฐํํด์ค.
- next ์๋ NULL์ ๋ด์์ฃผ์ด์ผ ํจ.
typedef struct s_list // ์ฐ๊ฒฐ ๋ฆฌ์คํธ์ ๋
ธ๋ ๊ตฌ์กฐ์ฒด
{
void *content; // ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ๋ฉค๋ฒ
struct s_list *next; // ๋ค์ ๋
ธ๋์ ์ฃผ์๋ฅผ ์ ์ฅํ ํฌ์ธํฐ
} t_list;