-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstadd_back_bonus.c
50 lines (46 loc) · 1.71 KB
/
ft_lstadd_back_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tcakir-y <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/18 12:09:01 by tcakir-y #+# #+# */
/* Updated: 2024/10/18 13:40:37 by tcakir-y ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *end_of_list;
end_of_list = ft_lstlast(*lst);
if (!end_of_list)
{
*lst = new;
return ;
}
end_of_list -> next = new;
}
//static void print_list(t_list *lst)
//{
// while (lst)
// {
// printf(" %s", (char *)lst -> content);
// lst = lst -> next;
// }
// printf(" end of list");
//}
//int main(void)
//{
// t_list *list = NULL;
// ft_lstadd_back(&list, ft_lstnew(" WORLD"));
// ft_lstadd_back(&list, ft_lstnew("!!"));
// ft_lstadd_back(&list, ft_lstnew("YAY"));
// print_list(list);
// return (0);
//}
//1. get the last element of the list
//2. set the last->next variable to point to the new element
//3. if last is NULL, make the list pointer point to the new element
// If the list is empty, make new the first element
// Otherwise, add new to the end of the list