aboutsummaryrefslogtreecommitdiff
path: root/c12
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-21 15:26:32 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-21 15:26:32 +0200
commit23ad79e8b41c25bb4992d103d29a17612a52e351 (patch)
tree9de3cde07cc38e59f08885171e9f99eeab8ab71b /c12
parent8b6e91bdb56bc01a588718472546f2a88e750b48 (diff)
downloadpiscine-23ad79e8b41c25bb4992d103d29a17612a52e351.tar.gz
piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.tar.bz2
piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.zip
c10 done, c11 on going, rush02 probably finished, bsq start
Diffstat (limited to 'c12')
-rw-r--r--c12/:w32
-rw-r--r--c12/ex02/ft_list.h4
-rw-r--r--c12/ex03/ft_list.h4
-rw-r--r--c12/ex06/ft_list.h4
-rw-r--r--c12/ex07/ft_list.h4
-rw-r--r--c12/ex08/ft_list.h22
-rw-r--r--c12/ex08/ft_list_reverse.c18
-rw-r--r--c12/ex09/ft_list.h4
-rw-r--r--c12/ex09/ft_list_foreach.c20
-rw-r--r--c12/ex10/ft_list.h22
-rw-r--r--c12/ex10/ft_list_foreach_if.c19
-rw-r--r--c12/ex11/ft_list.h22
-rw-r--r--c12/ex11/ft_list_find.c22
-rw-r--r--c12/ex12/ft_list.h22
-rw-r--r--c12/ex12/ft_list_remove_if.c30
-rw-r--r--c12/ex13/ft_list.h22
-rw-r--r--c12/ex13/ft_list_merge.c21
-rw-r--r--c12/ex14/ft_list.h22
-rw-r--r--c12/ex14/ft_list_sort.c45
-rw-r--r--c12/ex15/ft_list.h22
-rw-r--r--c12/ex15/ft_list_reverse_fun.c27
-rw-r--r--c12/ex16/ft_list.h24
-rw-r--r--c12/ex16/ft_sorted_list_insert.c16
-rw-r--r--c12/ex17/ft_list.h22
-rw-r--r--c12/main.c48
25 files changed, 444 insertions, 74 deletions
diff --git a/c12/:w b/c12/:w
deleted file mode 100644
index 2b1fe54..0000000
--- a/c12/:w
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <stdio.h>
-#include "ex00/ft_list.h"
-#include "ex00/ft_create_elem.c"
-#include "ex01/ft_list_push_front.c"
-/*#include "ex02/ft_list_size.c"*/
-/*#include "ex03/ft_list_last.c"*/
-/*#include "ex04/ft_list_push_back.c"*/
-/*#include "ex05/ft_list_push_strs.c"*/
-/*#include "ex06/ft_list_clear.c"*/
-/*#include "ex07/ft_list_at.c"*/
-/*#include "ex08/ft_list_reverse.c"*/
-/*#include "ex09/ft_list_foreach.c"*/
-/*#include "ex10/ft_list_foreach_if.c"*/
-/*#include "ex11/ft_list_find.c"*/
-/*#include "ex12/ft_list_remove_if.c"*/
-/*#include "ex13/ft_list_merge.c"*/
-/*#include "ex14/ft_list_sort.c"*/
-/*#include "ex15/ft_list_reverse_fun.c"*/
-/*#include "ex16/ft_sorted_list_insert.c"*/
-/*#include "ft_sorted_list_merge.c"*/
-
-int main()
-{
- t_list *list = NULL;
- int a = 4;
- void *data = &a;
-
- list = ft_create_elem(data);
- printf("%d\n", list->data);
-
-
-}
diff --git a/c12/ex02/ft_list.h b/c12/ex02/ft_list.h
index 8b736b4..33ad610 100644
--- a/c12/ex02/ft_list.h
+++ b/c12/ex02/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/09 14:42:55 by cacharle ### ########.fr */
+/* Updated: 2019/07/19 08:29:04 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,4 @@ typedef struct s_list
void *data;
} t_list;
-t_list *ft_create_elem(void *data);
-
#endif
diff --git a/c12/ex03/ft_list.h b/c12/ex03/ft_list.h
index 8b736b4..32a5925 100644
--- a/c12/ex03/ft_list.h
+++ b/c12/ex03/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/09 14:42:55 by cacharle ### ########.fr */
+/* Updated: 2019/07/19 08:28:53 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,4 @@ typedef struct s_list
void *data;
} t_list;
-t_list *ft_create_elem(void *data);
-
#endif
diff --git a/c12/ex06/ft_list.h b/c12/ex06/ft_list.h
index 8b736b4..aeb710e 100644
--- a/c12/ex06/ft_list.h
+++ b/c12/ex06/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/09 14:42:55 by cacharle ### ########.fr */
+/* Updated: 2019/07/19 08:28:35 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,4 @@ typedef struct s_list
void *data;
} t_list;
-t_list *ft_create_elem(void *data);
-
#endif
diff --git a/c12/ex07/ft_list.h b/c12/ex07/ft_list.h
index 8b736b4..ab7e2d1 100644
--- a/c12/ex07/ft_list.h
+++ b/c12/ex07/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/09 14:42:55 by cacharle ### ########.fr */
+/* Updated: 2019/07/19 08:28:24 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,4 @@ typedef struct s_list
void *data;
} t_list;
-t_list *ft_create_elem(void *data);
-
#endif
diff --git a/c12/ex08/ft_list.h b/c12/ex08/ft_list.h
new file mode 100644
index 0000000..0744591
--- /dev/null
+++ b/c12/ex08/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/ex08/ft_list_reverse.c b/c12/ex08/ft_list_reverse.c
index 23d4339..e5c2057 100644
--- a/c12/ex08/ft_list_reverse.c
+++ b/c12/ex08/ft_list_reverse.c
@@ -6,22 +6,24 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 18:05:23 by cacharle #+# #+# */
-/* Updated: 2019/07/17 19:13:19 by cacharle ### ########.fr */
+/* Updated: 2019/07/19 08:18:13 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
void ft_list_reverse(t_list **begin_list)
{
- t_list *tmp;
+ t_list *cursor;
t_list *prev;
+ t_list *tmp_next;
prev = NULL;
- tmp = (*begin_list)->next;
- while (tmp != NULL)
+ cursor = *begin_list;
+ while (cursor != NULL)
{
- (*begin_list)->next = prev;
- prev = *begin_list;
- *begin_list = tmp;
- tmp = (*begin_list)->next;
+ tmp_next = cursor->next;
+ cursor->next = prev;
+ prev = cursor;
+ cursor = tmp_next;
}
+ *begin_list = prev;
}
diff --git a/c12/ex09/ft_list.h b/c12/ex09/ft_list.h
index 08a22a5..8f3a487 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/17 17:11:04 by cacharle ### ########.fr */
+/* Updated: 2019/07/19 08:27:40 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,4 @@ typedef struct s_list
void *data;
} t_list;
-t_list *ft_create_elem(void *data);
-
#endif
diff --git a/c12/ex09/ft_list_foreach.c b/c12/ex09/ft_list_foreach.c
index e69de29..2c9705f 100644
--- a/c12/ex09/ft_list_foreach.c
+++ b/c12/ex09/ft_list_foreach.c
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_foreach.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+void ft_list_foreach(t_list *begin_list, void (*f)(void *))
+{
+ while (begin_list != NULL)
+ {
+ (*f)(begin_list->data);
+ begin_list = begin_list->next;
+ }
+}
diff --git a/c12/ex10/ft_list.h b/c12/ex10/ft_list.h
new file mode 100644
index 0000000..5a8dab5
--- /dev/null
+++ b/c12/ex10/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/ex10/ft_list_foreach_if.c b/c12/ex10/ft_list_foreach_if.c
index e69de29..944e31b 100644
--- a/c12/ex10/ft_list_foreach_if.c
+++ b/c12/ex10/ft_list_foreach_if.c
@@ -0,0 +1,19 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_foreach_if.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+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);
+}
diff --git a/c12/ex11/ft_list.h b/c12/ex11/ft_list.h
new file mode 100644
index 0000000..698a86c
--- /dev/null
+++ b/c12/ex11/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/ex11/ft_list_find.c b/c12/ex11/ft_list_find.c
index e69de29..e0d22e8 100644
--- a/c12/ex11/ft_list_find.c
+++ b/c12/ex11/ft_list_find.c
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_find.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)())
+{
+ while (begin_list != NULL)
+ {
+ if ((*cmp)(begin_list->data, data_ref) == 0)
+ break ;
+ begin_list = begin_list->next;
+ }
+ return (begin_list);
+}
diff --git a/c12/ex12/ft_list.h b/c12/ex12/ft_list.h
new file mode 100644
index 0000000..0f7f09a
--- /dev/null
+++ b/c12/ex12/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/ex12/ft_list_remove_if.c b/c12/ex12/ft_list_remove_if.c
index e69de29..dc7f310 100644
--- a/c12/ex12/ft_list_remove_if.c
+++ b/c12/ex12/ft_list_remove_if.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_remove_if.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *))
+{
+ t_list *prev;
+ t_list *cursor;
+
+ prev = NULL;
+ cursor = *begin_list;
+ while (cursor)
+ {
+ if ((*cmp)(cursor->data, data_ref))
+ {
+ if (prev)
+ prev->next = cursor->next;
+ (*free_fct)(cursor->data);
+ }
+ cursor = cursor->next;
+ }
+}
diff --git a/c12/ex13/ft_list.h b/c12/ex13/ft_list.h
new file mode 100644
index 0000000..f0a6674
--- /dev/null
+++ b/c12/ex13/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/ex13/ft_list_merge.c b/c12/ex13/ft_list_merge.c
index e69de29..4de2ff3 100644
--- a/c12/ex13/ft_list_merge.c
+++ b/c12/ex13/ft_list_merge.c
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_merge.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/19 08:50:01 by cacharle #+# #+# */
+/* Updated: 2019/07/19 08:51:36 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+void ft_list_merge(t_list **begin_list1, t_list *begin_list2)
+{
+ t_list *cursor;
+
+ cursor = *begin_list1;
+ while (cursor->next)
+ cursor = cursor->next;
+ cursor->next = begin_list2;
+}
diff --git a/c12/ex14/ft_list.h b/c12/ex14/ft_list.h
new file mode 100644
index 0000000..cf65023
--- /dev/null
+++ b/c12/ex14/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 14:33:17 by cacharle #+# #+# */
+/* Updated: 2019/07/19 08:26:25 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/ex14/ft_list_sort.c b/c12/ex14/ft_list_sort.c
index e69de29..698d345 100644
--- a/c12/ex14/ft_list_sort.c
+++ b/c12/ex14/ft_list_sort.c
@@ -0,0 +1,45 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_sort.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/19 13:43:11 by cacharle #+# #+# */
+/* Updated: 2019/07/19 13:53:54 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+static int is_sorted(t_list **begin_list, int (*cmp)())
+{
+ t_list *cursor;
+
+ while (cursor->next)
+ {
+ if ((*cmp)(cursor->data, cursor->next->data) > 0)
+ return (0);
+ cursor = cursor->next;
+ }
+ return (1);
+}
+
+void ft_list_sort(t_list **begin_list, int (*cmp)())
+{
+ t_list *cursor;
+ void *tmp;
+
+ while (!is_sorted(*begin_list, cmp))
+ {
+ cursor = *begin_list;
+ while (cursor->next)
+ {
+ if ((*cmp)(cursor->data, cursor->next->data) > 0)
+ {
+ tmp = cursor->data;
+ cursor->data = cursor->data->next;
+ cursor->data->next = tmp;
+ }
+ cursor = cursor->next;
+ }
+ }
+}
diff --git a/c12/ex15/ft_list.h b/c12/ex15/ft_list.h
new file mode 100644
index 0000000..5eafe75
--- /dev/null
+++ b/c12/ex15/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 14:33:17 by cacharle #+# #+# */
+/* Updated: 2019/07/19 08:26:12 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/ex15/ft_list_reverse_fun.c b/c12/ex15/ft_list_reverse_fun.c
index e69de29..9ee845e 100644
--- a/c12/ex15/ft_list_reverse_fun.c
+++ b/c12/ex15/ft_list_reverse_fun.c
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_reverse_fun.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/19 13:55:34 by cacharle #+# #+# */
+/* Updated: 2019/07/20 08:18:04 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+static t_list *reverse_rec(t_list *begin_list)
+{
+ if (!begin_list)
+ return begin_list;
+ if (!begin_list->next)
+ return begin_list;
+ ft_list_reverse_fun(begin_list->next);
+ begin_list->next->next = begin_list;
+ begin_list->next = NULL;
+}
+
+void ft_list_reverse_fun(t_list *begin_list)
+{
+ begin_list = reverse_rec(begin_list);
+}
diff --git a/c12/ex16/ft_list.h b/c12/ex16/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex16/ft_list.h
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+t_list *ft_create_elem(void *data);
+
+#endif
diff --git a/c12/ex16/ft_sorted_list_insert.c b/c12/ex16/ft_sorted_list_insert.c
index e69de29..2ca345a 100644
--- a/c12/ex16/ft_sorted_list_insert.c
+++ b/c12/ex16/ft_sorted_list_insert.c
@@ -0,0 +1,16 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sorted_list_insert.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/20 08:19:32 by cacharle #+# #+# */
+/* Updated: 2019/07/20 08:23:17 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)())
+{
+
+}
diff --git a/c12/ex17/ft_list.h b/c12/ex17/ft_list.h
new file mode 100644
index 0000000..ef3a012
--- /dev/null
+++ b/c12/ex17/ft_list.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 14:33:17 by cacharle #+# #+# */
+/* Updated: 2019/07/19 08:25:54 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
diff --git a/c12/main.c b/c12/main.c
index f0ed68a..3f0d8c5 100644
--- a/c12/main.c
+++ b/c12/main.c
@@ -24,34 +24,40 @@ void ft_free(void *data);
int main()
{
+ int a = 1;
+ int b = 2;
+ int c = 3;
+ int d = 4;
+ int e = 5;
+ int f = 6;
+ int g = 7;
t_list *list = NULL;
- int a = 4;
- void *data = &a;
- list = ft_create_elem(data);
- printf("%d\n", *(int*)list->data);
+ list = ft_create_elem(&a);
+ printf("%d", *(int*)list->data);
- char b = 'g';
- data = &b;
- ft_list_push_front(&list, data);
- printf("%c\n", *(char*)list->data);
- printf("%d\n", *(char*)list->next->data);
- printf("%s\n", (char*)list->next->next);
+ printf("\n--------------\n");
+ ft_list_push_front(&list, &b);
+ printf("%d\n", *(int*)list->data);
+ printf("%d\n", *(int*)list->next->data);
+ printf("%s", (char*)list->next->next);
+ printf("\n--------------\n");
printf("size %d\n", ft_list_size(list));
- ft_list_push_front(&list, data);
- printf("size %d\n", ft_list_size(list));
+ ft_list_push_front(&list, &c);
+ printf("size %d", ft_list_size(list));
- printf("last %d\n", *(int*)ft_list_last(list)->data);
+ printf("\n--------------\n");
+ printf("last %d", *(int*)ft_list_last(list)->data);
- double c = 3.14;
- data = &c;
- ft_list_push_back(&list, data);
- printf("list last %f\n", *(double*)ft_list_last(list)->data);
+ printf("\n--------------\n");
+ ft_list_push_back(&list, &c);
+ printf("list last %d\n", *(int*)ft_list_last(list)->data);
t_list *empty = NULL;
- ft_list_push_back(&empty, data);
- printf("empty last %f\n", *(double*)ft_list_last(list)->data);
+ ft_list_push_back(&empty, &e);
+ printf("empty last %d\n", *(int*)ft_list_last(empty)->data);
+ printf("\n--------------\n");
char **strs = malloc(sizeof(char*) * 4);
strs[0] = malloc(sizeof(char) * 32);
strs[1] = malloc(sizeof(char) * 32);
@@ -72,6 +78,10 @@ int main()
printf("%f\n", *(double*)(ft_list_at(list, 1)->data));
printf("%s\n", (char*)ft_list_at(list, 2));
+ printf("\n--------------\n");
+ // reverse
+
+ printf("\n--------------\n");
}