aboutsummaryrefslogtreecommitdiff
path: root/c12/ex04
diff options
context:
space:
mode:
Diffstat (limited to 'c12/ex04')
-rw-r--r--c12/ex04/ft_list.h6
-rw-r--r--c12/ex04/ft_list_push_back.c17
2 files changed, 13 insertions, 10 deletions
diff --git a/c12/ex04/ft_list.h b/c12/ex04/ft_list.h
index 8b736b4..3ea2dcb 100644
--- a/c12/ex04/ft_list.h
+++ b/c12/ex04/ft_list.h
@@ -6,12 +6,12 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 14:33:17 by cacharle #+# #+# */
-/* Updated: 2019/07/09 14:42:55 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:19:58 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
@@ -19,6 +19,6 @@ typedef struct s_list
void *data;
} t_list;
-t_list *ft_create_elem(void *data);
+t_list *ft_create_elem(void *data);
#endif
diff --git a/c12/ex04/ft_list_push_back.c b/c12/ex04/ft_list_push_back.c
index db4fdb0..b4c486b 100644
--- a/c12/ex04/ft_list_push_back.c
+++ b/c12/ex04/ft_list_push_back.c
@@ -6,23 +6,26 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 17:18:46 by cacharle #+# #+# */
-/* Updated: 2019/07/17 18:04:28 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:42:15 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
+#include <stdlib.h>
#include "ft_list.h"
-void ft_list_push_back(t_list **begin_list, void *data)
+void ft_list_push_back(t_list **begin_list, void *data)
{
t_list *new_rear;
+ t_list *cursor;
new_rear = ft_create_elem(data);
- if (!*begin_list)
+ if (*begin_list == NULL)
{
- (*begin_list) = new_rear;
+ *begin_list = new_rear;
return ;
}
- while ((*begin_list)->next)
- *begin_list = (*begin_list)->next;
- (*begin_list)->next = new_rear;
+ cursor = *begin_list;
+ while (cursor->next)
+ cursor = cursor->next;
+ cursor->next = new_rear;
}