File tree Expand file tree Collapse file tree 4 files changed +23
-9
lines changed
libraries/libft/src/lists/singly_linked Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Original file line number Diff line number Diff line change 6
6
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2024/02/11 00:35:15 by ldulling #+# #+# */
9
- /* Updated: 2025/05/28 19:29:42 by ldulling ### ########.fr */
9
+ /* Updated: 2025/05/28 21:34:35 by ldulling ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
20
20
*
21
21
* @param lst The address of the pointer to the first node of the list.
22
22
* @param tail The address of the pointer to the last node of the list.
23
+ * If tail (not *tail) is NULL, it is ignored.
23
24
* @param new The new node to be added to the list.
25
+ * If new is NULL, the function does nothing.
24
26
*
25
27
* @return No return value.
26
28
*
27
29
*/
28
30
void ft_lstadd_back_tail (t_list * * lst , t_list * * tail , t_list * new )
29
31
{
30
- if (* lst == NULL )
31
- * lst = new ;
32
+ if (lst == NULL || tail == NULL || new == NULL )
33
+ {
34
+ ft_lstadd_back (lst , new );
35
+ return ;
36
+ }
37
+ if (* lst == NULL || * tail == NULL )
38
+ ft_lstadd_back (lst , new );
32
39
else
33
40
(* tail )-> next = new ;
34
41
* tail = new ;
Original file line number Diff line number Diff line change 6
6
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2024/01/06 20:30:19 by ldulling #+# #+# */
9
- /* Updated: 2024/01/17 11:42:57 by ldulling ### ########.fr */
9
+ /* Updated: 2025/05/28 20:14:28 by ldulling ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
20
20
* @param content The content to be added to the new node.
21
21
*
22
22
* @return Returns true if the new node was successfully added, false
23
- * if malloc failed.
23
+ * if malloc failed or lst (not *lst) is NULL .
24
24
*
25
25
*/
26
26
bool ft_lstnew_back (t_list * * lst , void * content )
27
27
{
28
28
t_list * new_node ;
29
29
30
+ if (lst == NULL )
31
+ return (false);
30
32
new_node = ft_lstnew (content );
31
33
if (new_node == NULL )
32
34
return (false);
Original file line number Diff line number Diff line change 6
6
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2024/06/07 19:11:17 by ldulling #+# #+# */
9
- /* Updated: 2025/05/28 19:26:46 by ldulling ### ########.fr */
9
+ /* Updated: 2025/05/28 20:24:43 by ldulling ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
20
20
*
21
21
* @param lst The address of the list to add the new node to.
22
22
* @param tail The address of the pointer to the last node of the list.
23
+ * If tail (not *tail) is NULL, it is ignored.
23
24
* @param content The content to be added to the new node.
24
25
*
25
26
* @return Returns true if the new node was successfully added, false
26
- * if malloc failed.
27
+ * if malloc failed or lst (not *lst) is NULL .
27
28
*
28
29
*/
29
30
bool ft_lstnew_back_tail (t_list * * lst , t_list * * tail , void * content )
30
31
{
31
32
t_list * new_node ;
32
33
34
+ if (lst == NULL || tail == NULL )
35
+ return (ft_lstnew_back (lst , content ));
33
36
new_node = ft_lstnew (content );
34
37
if (new_node == NULL )
35
38
return (false);
Original file line number Diff line number Diff line change 6
6
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2024/01/25 16:09:14 by ldulling #+# #+# */
9
- /* Updated: 2024/01/25 16:09:17 by ldulling ### ########.fr */
9
+ /* Updated: 2025/05/28 20:14:18 by ldulling ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
20
20
* @param content The content to be added to the new node.
21
21
*
22
22
* @return Returns true if the new node was successfully added, false if
23
- * malloc failed.
23
+ * malloc failed or lst (not *lst) is NULL .
24
24
*
25
25
*/
26
26
bool ft_lstnew_front (t_list * * lst , void * content )
27
27
{
28
28
t_list * new_node ;
29
29
30
+ if (lst == NULL )
31
+ return (false);
30
32
new_node = ft_lstnew (content );
31
33
if (new_node == NULL )
32
34
return (false);
You can’t perform that action at this time.
0 commit comments