aboutsummaryrefslogtreecommitdiff
path: root/c12
diff options
context:
space:
mode:
authorCabergs Charles <cacharle@e-r6-p7.s19.be>2019-07-24 08:02:55 +0200
committerCabergs Charles <cacharle@e-r6-p7.s19.be>2019-07-24 08:02:55 +0200
commite7acdc820fefa41ae00a7c776388e3d17250a2e9 (patch)
tree5604e51c0008088f25b2f5dfb9143a852dd079dd /c12
parent454d82f30e354e2629563822bac637e5eaa8e4ff (diff)
downloadpiscine-e7acdc820fefa41ae00a7c776388e3d17250a2e9.tar.gz
piscine-e7acdc820fefa41ae00a7c776388e3d17250a2e9.tar.bz2
piscine-e7acdc820fefa41ae00a7c776388e3d17250a2e9.zip
c12 passed, c13 start
Diffstat (limited to 'c12')
-rw-r--r--c12/ex00/ft_create_elem.c6
-rw-r--r--c12/ex00/ft_list.h6
-rw-r--r--c12/ex01/ft_list.h6
-rw-r--r--c12/ex01/ft_list_push_front.c4
-rw-r--r--c12/ex02/ft_list.h4
-rw-r--r--c12/ex03/ft_list.h4
-rw-r--r--c12/ex03/ft_list_last.c5
-rw-r--r--c12/ex04/ft_list.h6
-rw-r--r--c12/ex04/ft_list_push_back.c17
-rw-r--r--c12/ex05/ft_list.h6
-rw-r--r--c12/ex05/ft_list_push_strs.c11
-rw-r--r--c12/ex06/ft_list.h4
-rw-r--r--c12/ex06/ft_list_clear.c7
-rw-r--r--c12/ex07/ft_list.h4
-rw-r--r--c12/ex07/ft_list_at.c7
-rw-r--r--c12/ex08/ft_list.h4
-rw-r--r--c12/ex08/ft_list_reverse.c7
-rw-r--r--c12/ex09/ft_list.h2
-rw-r--r--c12/ex09/ft_list_foreach.c7
-rw-r--r--c12/ex10/ft_list.h4
-rw-r--r--c12/ex10/ft_list_foreach_if.c12
-rw-r--r--c12/ex11/ft_list.h4
-rw-r--r--c12/ex11/ft_list_find.c7
-rw-r--r--c12/ex12/ft_list.h4
-rw-r--r--c12/ex12/ft_list_remove_if.c26
-rw-r--r--c12/ex13/ft_list.h4
-rw-r--r--c12/ex13/ft_list_merge.c9
-rw-r--r--c12/ex14/ft_list.h4
-rw-r--r--c12/ex14/ft_list_sort.c19
-rw-r--r--c12/ex15/ft_list.h4
-rw-r--r--c12/ex15/ft_list_reverse_fun.c47
-rw-r--r--c12/ex16/ft_list.h6
-rw-r--r--c12/ex16/ft_sorted_list_insert.c24
-rw-r--r--c12/ex17/ft_list.h4
-rw-r--r--c12/ex17/ft_sorted_list_merge.c47
-rw-r--r--c12/main.c159
36 files changed, 373 insertions, 128 deletions
diff --git a/c12/ex00/ft_create_elem.c b/c12/ex00/ft_create_elem.c
index 092833b..472595c 100644
--- a/c12/ex00/ft_create_elem.c
+++ b/c12/ex00/ft_create_elem.c
@@ -6,18 +6,18 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 17:19:22 by cacharle #+# #+# */
-/* Updated: 2019/07/17 18:34:23 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:16:58 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "ft_list.h"
-t_list *ft_create_elem(void *data)
+t_list *ft_create_elem(void *data)
{
t_list *list;
- if((list = (t_list*)malloc(sizeof(t_list))) == NULL)
+ if ((list = (t_list*)malloc(sizeof(t_list))) == NULL)
return (NULL);
list->data = data;
list->next = NULL;
diff --git a/c12/ex00/ft_list.h b/c12/ex00/ft_list.h
index 8b736b4..686f459 100644
--- a/c12/ex00/ft_list.h
+++ b/c12/ex00/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:18:55 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/ex01/ft_list.h b/c12/ex01/ft_list.h
index 8b736b4..a7a433c 100644
--- a/c12/ex01/ft_list.h
+++ b/c12/ex01/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:22 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/ex01/ft_list_push_front.c b/c12/ex01/ft_list_push_front.c
index 76fedd9..867b007 100644
--- a/c12/ex01/ft_list_push_front.c
+++ b/c12/ex01/ft_list_push_front.c
@@ -6,11 +6,11 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 17:19:14 by cacharle #+# #+# */
-/* Updated: 2019/07/17 17:10:46 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:16:43 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-
+#include <stdlib.h>
#include "ft_list.h"
void ft_list_push_front(t_list **begin_list, void *data)
diff --git a/c12/ex02/ft_list.h b/c12/ex02/ft_list.h
index 33ad610..c98b98d 100644
--- a/c12/ex02/ft_list.h
+++ b/c12/ex02/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/19 08:29:04 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:17:13 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex03/ft_list.h b/c12/ex03/ft_list.h
index 32a5925..0167a74 100644
--- a/c12/ex03/ft_list.h
+++ b/c12/ex03/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/19 08:28:53 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:17:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex03/ft_list_last.c b/c12/ex03/ft_list_last.c
index 84a46c2..2164e34 100644
--- a/c12/ex03/ft_list_last.c
+++ b/c12/ex03/ft_list_last.c
@@ -6,14 +6,17 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 17:18:58 by cacharle #+# #+# */
-/* Updated: 2019/07/17 17:30:36 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:37:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
+#include <stdlib.h>
#include "ft_list.h"
t_list *ft_list_last(t_list *begin_list)
{
+ if (begin_list == NULL)
+ return (NULL);
while (begin_list->next != NULL)
begin_list = begin_list->next;
return (begin_list);
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;
}
diff --git a/c12/ex05/ft_list.h b/c12/ex05/ft_list.h
index 8b736b4..b5a05a2 100644
--- a/c12/ex05/ft_list.h
+++ b/c12/ex05/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:36 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/ex05/ft_list_push_strs.c b/c12/ex05/ft_list_push_strs.c
index e56cd18..43c24a7 100644
--- a/c12/ex05/ft_list_push_strs.c
+++ b/c12/ex05/ft_list_push_strs.c
@@ -6,13 +6,14 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 17:18:23 by cacharle #+# #+# */
-/* Updated: 2019/07/17 18:34:23 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:42:33 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
+#include <stdlib.h>
#include "ft_list.h"
-void list_push_front(t_list **begin_list, void *data)
+static void push_front(t_list **begin_list, void *data)
{
t_list *new_front;
@@ -21,14 +22,14 @@ void list_push_front(t_list **begin_list, void *data)
*begin_list = new_front;
}
-t_list *ft_list_push_strs(int size, char **strs)
+t_list *ft_list_push_strs(int size, char **strs)
{
- int i;
+ int i;
t_list *list;
list = NULL;
i = 0;
while (i < size)
- list_push_front(&list, strs[i++]);
+ push_front(&list, strs[i++]);
return (list);
}
diff --git a/c12/ex06/ft_list.h b/c12/ex06/ft_list.h
index aeb710e..d64c942 100644
--- a/c12/ex06/ft_list.h
+++ b/c12/ex06/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/19 08:28:35 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:18:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex06/ft_list_clear.c b/c12/ex06/ft_list_clear.c
index 811469b..2263bf0 100644
--- a/c12/ex06/ft_list_clear.c
+++ b/c12/ex06/ft_list_clear.c
@@ -6,18 +6,17 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 17:53:02 by cacharle #+# #+# */
-/* Updated: 2019/07/17 18:20:11 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:42:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
+#include <stdlib.h>
#include "ft_list.h"
-void ft_list_clear(t_list *begin_list, void (*free_fct)(void *))
+void ft_list_clear(t_list *begin_list, void (*free_fct)(void *))
{
t_list *tmp;
- if (begin_list == NULL)
- return ;
while (begin_list)
{
free_fct(begin_list->data);
diff --git a/c12/ex07/ft_list.h b/c12/ex07/ft_list.h
index ab7e2d1..3888011 100644
--- a/c12/ex07/ft_list.h
+++ b/c12/ex07/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/19 08:28:24 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:18:13 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex07/ft_list_at.c b/c12/ex07/ft_list_at.c
index ad4b084..3e4d7ca 100644
--- a/c12/ex07/ft_list_at.c
+++ b/c12/ex07/ft_list_at.c
@@ -6,15 +6,16 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 17:56:31 by cacharle #+# #+# */
-/* Updated: 2019/07/17 18:36:07 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:42:59 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
+#include <stdlib.h>
#include "ft_list.h"
-t_list *ft_list_at(t_list *begin_list, unsigned int nbr)
+t_list *ft_list_at(t_list *begin_list, unsigned int nbr)
{
- while (nbr-- > 0 && begin_list)
+ while (nbr-- > 0 && begin_list != NULL)
begin_list = begin_list->next;
return (begin_list);
}
diff --git a/c12/ex08/ft_list.h b/c12/ex08/ft_list.h
index 0744591..d4fdda0 100644
--- a/c12/ex08/ft_list.h
+++ b/c12/ex08/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/19 08:28:13 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:18:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex08/ft_list_reverse.c b/c12/ex08/ft_list_reverse.c
index e5c2057..a849c3a 100644
--- a/c12/ex08/ft_list_reverse.c
+++ b/c12/ex08/ft_list_reverse.c
@@ -6,11 +6,14 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 18:05:23 by cacharle #+# #+# */
-/* Updated: 2019/07/19 08:18:13 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:42:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-void ft_list_reverse(t_list **begin_list)
+#include <stdlib.h>
+#include "ft_list.h"
+
+void ft_list_reverse(t_list **begin_list)
{
t_list *cursor;
t_list *prev;
diff --git a/c12/ex09/ft_list.h b/c12/ex09/ft_list.h
index 8f3a487..c46b6e5 100644
--- a/c12/ex09/ft_list.h
+++ b/c12/ex09/ft_list.h
@@ -6,7 +6,7 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 14:33:17 by cacharle #+# #+# */
-/* Updated: 2019/07/19 08:27:40 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:18:29 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/c12/ex09/ft_list_foreach.c b/c12/ex09/ft_list_foreach.c
index 2c9705f..15fe1ef 100644
--- a/c12/ex09/ft_list_foreach.c
+++ b/c12/ex09/ft_list_foreach.c
@@ -6,11 +6,14 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/19 08:29:57 by cacharle #+# #+# */
-/* Updated: 2019/07/19 08:31:03 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:43:14 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-void ft_list_foreach(t_list *begin_list, void (*f)(void *))
+#include <stdlib.h>
+#include "ft_list.h"
+
+void ft_list_foreach(t_list *begin_list, void (*f)(void *))
{
while (begin_list != NULL)
{
diff --git a/c12/ex10/ft_list.h b/c12/ex10/ft_list.h
index 5a8dab5..7cecff1 100644
--- a/c12/ex10/ft_list.h
+++ b/c12/ex10/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/19 08:27:25 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:20:47 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex10/ft_list_foreach_if.c b/c12/ex10/ft_list_foreach_if.c
index 944e31b..4fd6d73 100644
--- a/c12/ex10/ft_list_foreach_if.c
+++ b/c12/ex10/ft_list_foreach_if.c
@@ -6,14 +6,20 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/19 08:31:11 by cacharle #+# #+# */
-/* Updated: 2019/07/19 08:34:48 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:44:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), void
- *data_ref, int (*cmp)())
+#include <stdlib.h>
+#include "ft_list.h"
+
+void ft_list_foreach_if(t_list *begin_list, void (*f)(void *),
+ void *data_ref, int (*cmp)())
{
while (begin_list != NULL)
+ {
if ((*cmp)(begin_list->data, data_ref) == 0)
(*f)(begin_list->data);
+ begin_list = begin_list->next;
+ }
}
diff --git a/c12/ex11/ft_list.h b/c12/ex11/ft_list.h
index 698a86c..ca62a2f 100644
--- a/c12/ex11/ft_list.h
+++ b/c12/ex11/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/19 08:27:07 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:21:14 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex11/ft_list_find.c b/c12/ex11/ft_list_find.c
index e0d22e8..00d7903 100644
--- a/c12/ex11/ft_list_find.c
+++ b/c12/ex11/ft_list_find.c
@@ -6,11 +6,14 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/19 08:35:32 by cacharle #+# #+# */
-/* Updated: 2019/07/19 08:38:01 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:43:57 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)())
+#include <stdlib.h>
+#include "ft_list.h"
+
+t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)())
{
while (begin_list != NULL)
{
diff --git a/c12/ex12/ft_list.h b/c12/ex12/ft_list.h
index 0f7f09a..3edec35 100644
--- a/c12/ex12/ft_list.h
+++ b/c12/ex12/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/19 08:26:52 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:21:53 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex12/ft_list_remove_if.c b/c12/ex12/ft_list_remove_if.c
index dc7f310..c6821b8 100644
--- a/c12/ex12/ft_list_remove_if.c
+++ b/c12/ex12/ft_list_remove_if.c
@@ -6,25 +6,39 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/19 08:38:28 by cacharle #+# #+# */
-/* Updated: 2019/07/19 08:49:43 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:41:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *))
+#include <stdlib.h>
+#include "ft_list.h"
+
+void ft_list_remove_if(t_list **begin_list, void *data_ref,
+ int (*cmp)(), void (*free_fct)(void *))
{
t_list *prev;
t_list *cursor;
+ t_list *tmp;
prev = NULL;
cursor = *begin_list;
- while (cursor)
+ while (cursor != NULL)
{
- if ((*cmp)(cursor->data, data_ref))
+ while (cursor && (*cmp)(cursor->data, data_ref) == 0)
{
- if (prev)
+ if (prev != NULL)
prev->next = cursor->next;
+ else
+ *begin_list = cursor->next;
(*free_fct)(cursor->data);
+ tmp = cursor;
+ cursor = cursor->next;
+ free(tmp);
+ }
+ if (cursor != NULL)
+ {
+ prev = cursor;
+ cursor = cursor->next;
}
- cursor = cursor->next;
}
}
diff --git a/c12/ex13/ft_list.h b/c12/ex13/ft_list.h
index f0a6674..aa23ccf 100644
--- a/c12/ex13/ft_list.h
+++ b/c12/ex13/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/19 08:26:38 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:22:12 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex13/ft_list_merge.c b/c12/ex13/ft_list_merge.c
index 4de2ff3..34c9614 100644
--- a/c12/ex13/ft_list_merge.c
+++ b/c12/ex13/ft_list_merge.c
@@ -6,15 +6,20 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */