aboutsummaryrefslogtreecommitdiff
path: root/c12
diff options
context:
space:
mode:
Diffstat (limited to 'c12')
-rw-r--r--c12/ex00/ft_create_elem.c24
-rw-r--r--c12/ex00/ft_list.h24
-rw-r--r--c12/ex01/ft_list.h24
-rw-r--r--c12/ex01/ft_list_push_front.c24
-rw-r--r--c12/ex02/ft_list.h24
-rw-r--r--c12/ex02/ft_list_size.c26
-rw-r--r--c12/ex03/ft_list.h24
-rw-r--r--c12/ex03/ft_list_last.c20
-rw-r--r--c12/ex04/ft_list.h24
-rw-r--r--c12/ex04/ft_list_push_back.c25
-rw-r--r--c12/ex05/ft_list.h24
-rw-r--r--c12/ex05/ft_list_push_strs.c30
-rw-r--r--c12/ex06/ft_list.h24
-rw-r--r--c12/ex06/ft_list_clear.c28
-rw-r--r--c12/ex07/ft_list.h24
-rw-r--r--c12/ex07/ft_list_at.c26
-rw-r--r--c12/ex08/ft_list_reverse.c22
-rw-r--r--c12/ex09/ft_list.h24
18 files changed, 441 insertions, 0 deletions
diff --git a/c12/ex00/ft_create_elem.c b/c12/ex00/ft_create_elem.c
new file mode 100644
index 0000000..8b6996a
--- /dev/null
+++ b/c12/ex00/ft_create_elem.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_create_elem.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:19:22 by cacharle #+# #+# */
+/* Updated: 2019/07/09 17:19:24 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+t_list *ft_create_elem(void *data)
+{
+ t_list *list;
+
+ list = (t_list*)malloc(sizeof(t_list));
+ list->data = data;
+ list->next = NULL;
+ return (list);
+}
diff --git a/c12/ex00/ft_list.h b/c12/ex00/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex00/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/ex01/ft_list.h b/c12/ex01/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex01/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/ex01/ft_list_push_front.c b/c12/ex01/ft_list_push_front.c
new file mode 100644
index 0000000..788fce1
--- /dev/null
+++ b/c12/ex01/ft_list_push_front.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_push_front.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:19:14 by cacharle #+# #+# */
+/* Updated: 2019/07/09 17:19:15 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+void ft_list_push_front(t_list **begin_list, void *data)
+{
+ t_list new_front;
+
+ new_front = (t_list*)malloc(sizeof(t_list));
+ new_front->data = data;
+ new_front->next = *begin_list;
+ if (*begin_list)
+ *begin_list = new_front;
+}
diff --git a/c12/ex02/ft_list.h b/c12/ex02/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex02/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/ex02/ft_list_size.c b/c12/ex02/ft_list_size.c
new file mode 100644
index 0000000..4380a02
--- /dev/null
+++ b/c12/ex02/ft_list_size.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_size.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:19:06 by cacharle #+# #+# */
+/* Updated: 2019/07/09 17:19:07 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+int ft_list_size(t_list *begin_list)
+{
+ int counter;
+
+ counter = 0;
+ while (begin_list)
+ {
+ counter++;
+ begin_list = begin_list->next;
+ }
+ return (counter);
+}
diff --git a/c12/ex03/ft_list.h b/c12/ex03/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex03/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/ex03/ft_list_last.c b/c12/ex03/ft_list_last.c
new file mode 100644
index 0000000..0446f76
--- /dev/null
+++ b/c12/ex03/ft_list_last.c
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_last.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:18:58 by cacharle #+# #+# */
+/* Updated: 2019/07/09 17:18:59 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+t_list *ft_list_last(t_list *begin_list)
+{
+ while (begin_list->next)
+ begin_list = begin_list->next;
+ return (begin_list);
+}
diff --git a/c12/ex04/ft_list.h b/c12/ex04/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex04/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/ex04/ft_list_push_back.c b/c12/ex04/ft_list_push_back.c
new file mode 100644
index 0000000..cfde9a8
--- /dev/null
+++ b/c12/ex04/ft_list_push_back.c
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_push_back.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:18:46 by cacharle #+# #+# */
+/* Updated: 2019/07/09 17:18:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+void ft_list_push_back(t_list **begin_list, void *data)
+{
+ if (*begin_list)
+ while (*begin_list->next)
+ *begin_list = *begin_list->next;
+ elem = ft_create_elem(data);
+ if (*begin_list)
+ *begin_list->next = elem;
+ else
+ *begin_list = elem;
+}
diff --git a/c12/ex05/ft_list.h b/c12/ex05/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex05/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/ex05/ft_list_push_strs.c b/c12/ex05/ft_list_push_strs.c
new file mode 100644
index 0000000..516fa7e
--- /dev/null
+++ b/c12/ex05/ft_list_push_strs.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_push_strs.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:18:23 by cacharle #+# #+# */
+/* Updated: 2019/07/09 17:52:44 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+t_list *ft_list_push_strs(int size, char **strs)
+{
+ int i;
+ t_list elem;
+ t_list next;
+
+ next = NULL;
+ i = 0;
+ while (i < size)
+ {
+ elem = ft_create_elem(strs[i]);
+ elem->next = next;
+ next = elem;
+ }
+ return (&elem);
+}
diff --git a/c12/ex06/ft_list.h b/c12/ex06/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex06/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/ex06/ft_list_clear.c b/c12/ex06/ft_list_clear.c
new file mode 100644
index 0000000..9a7cf5d
--- /dev/null
+++ b/c12/ex06/ft_list_clear.c
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_clear.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:53:02 by cacharle #+# #+# */
+/* Updated: 2019/07/09 18:02:09 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+void ft_list_clear(t_list *begin_list, void (*free_fct)(void *))
+{
+ t_list tmp;
+
+ if (!begin_list)
+ return ;
+ while (begin_list->next)
+ {
+ free_fct(begin_list->data);
+ tmp = begin_list->next;
+ free(begin_list);
+ begin_list = tmp;
+ }
+}
diff --git a/c12/ex07/ft_list.h b/c12/ex07/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex07/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/ex07/ft_list_at.c b/c12/ex07/ft_list_at.c
new file mode 100644
index 0000000..5176a76
--- /dev/null
+++ b/c12/ex07/ft_list_at.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_at.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 17:56:31 by cacharle #+# #+# */
+/* Updated: 2019/07/09 18:01:18 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+t_list *ft_list_at(t_list *begin_list, unsigned int nbr)
+{
+ int i;
+
+ i = 0;
+ while (i < nbr && begin_list)
+ {
+ begin_list = begin_list->next;
+ i++;
+ }
+ return (begin_list);
+}
diff --git a/c12/ex08/ft_list_reverse.c b/c12/ex08/ft_list_reverse.c
new file mode 100644
index 0000000..b650329
--- /dev/null
+++ b/c12/ex08/ft_list_reverse.c
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_reverse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/09 18:05:23 by cacharle #+# #+# */
+/* Updated: 2019/07/09 18:10:50 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+void ft_list_reverse(t_list **begin_list)
+{
+ t_list tmp;
+ while (*begin_list->next)
+ {
+ tmp = *begin_list->next;
+
+
+ }
+}
diff --git a/c12/ex09/ft_list.h b/c12/ex09/ft_list.h
new file mode 100644
index 0000000..8b736b4
--- /dev/null
+++ b/c12/ex09/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