diff options
53 files changed, 698 insertions, 132 deletions
diff --git a/c01/ex07/ft_rev_int_tab.c b/c01/ex07/ft_rev_int_tab.c index e6b0dea..82922d6 100644 --- a/c01/ex07/ft_rev_int_tab.c +++ b/c01/ex07/ft_rev_int_tab.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/03 18:02:02 by cacharle #+# #+# */ -/* Updated: 2019/07/04 06:44:57 by cacharle ### ########.fr */ +/* Updated: 2019/07/22 09:59:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,14 +31,14 @@ int main() printf("---------------\n"); int *rult; - int len = ft_ultimate_range(&rult, 0, INT_MAX); + int len = ft_ultimate_range(&rult, 0, 10); printf("len(%d): ", len); for (int i = 0; i < len; i++) printf("%d ", rult[i]); printf("\n "); printf("---------------\n"); - char *strs[] = {"bon", "je", "suis", "charles"}; + char *strs[] = {"bon", "je", "", "charles"}; char *sep = "%&^"; int size = 4; char *join; 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> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/19 08:50:01 by cacharle #+# #+# */ -/* Updated: 2019/07/19 08:51:36 by cacharle ### ########.fr */ +/* Updated: 2019/07/23 15:40:47 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -void ft_list_merge(t_list **begin_list1, t_list *begin_list2) +#include <stdlib.h> +#include "ft_list.h" + +void ft_list_merge(t_list **begin_list1, t_list *begin_list2) { t_list *cursor; cursor = *begin_list1; + if (cursor == NULL) + *begin_list1 = begin_list2; while (cursor->next) cursor = cursor->next; cursor->next = begin_list2; diff --git a/c12/ex14/ft_list.h b/c12/ex14/ft_list.h index cf65023..059a1aa 100644 --- a/c12/ex14/ft_list.h +++ b/c12/ex14/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:25 by cacharle ### ########.fr */ +/* Updated: 2019/07/23 15:22:22 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H -#define FT_LIST_H +# define FT_LIST_H typedef struct s_list { diff --git a/c12/ex14/ft_list_sort.c b/c12/ex14/ft_list_sort.c index 698d345..0d81425 100644 --- a/c12/ex14/ft_list_sort.c +++ b/c12/ex14/ft_list_sort.c @@ -6,14 +6,19 @@ /* 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 */ +/* Updated: 2019/07/23 15:41:20 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -static int is_sorted(t_list **begin_list, int (*cmp)()) -{ - t_list *cursor; +#include <stdlib.h> +#include "ft_list.h" +static int is_sorted(t_list *cursor, int (*cmp)()) +{ + if (cursor == NULL) + return (1); + else if (cursor->next == NULL) + return (1); while (cursor->next) { if ((*cmp)(cursor->data, cursor->next->data) > 0) @@ -23,7 +28,7 @@ static int is_sorted(t_list **begin_list, int (*cmp)()) return (1); } -void ft_list_sort(t_list **begin_list, int (*cmp)()) +void ft_list_sort(t_list **begin_list, int (*cmp)()) { t_list *cursor; void *tmp; @@ -36,8 +41,8 @@ void ft_list_sort(t_list **begin_list, int (*cmp)()) if ((*cmp)(cursor->data, cursor->next->data) > 0) { tmp = cursor->data; - cursor->data = cursor->data->next; - cursor->data->next = tmp; + cursor->data = cursor->next->data; + cursor->next->data = tmp; } cursor = cursor->next; } diff --git a/c12/ex15/ft_list.h b/c12/ex15/ft_list.h index 5eafe75..3fd2c68 100644 --- a/c12/ex15/ft_list.h +++ b/c12/ex15/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:12 by cacharle ### ########.fr */ +/* Updated: 2019/07/23 15:22:30 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H -#define FT_LIST_H +# define FT_LIST_H typedef struct s_list { diff --git a/c12/ex15/ft_list_reverse_fun.c b/c12/ex15/ft_list_reverse_fun.c index 9ee845e..ffbeea2 100644 --- a/c12/ex15/ft_list_reverse_fun.c +++ b/c12/ex15/ft_list_reverse_fun.c @@ -6,22 +6,47 @@ /* 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 */ +/* Updated: 2019/07/23 15:44:23 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -static t_list *reverse_rec(t_list *begin_list) +#include <stdlib.h> +#include "ft_list.h" + +static t_list *my_at(t_list *begin_list, int nbr) +{ + while (nbr-- > 0 && begin_list != NULL) + begin_list = begin_list->next; + return (begin_list); +} + +static int my_size(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; + int counter; + + counter = 0; + while (begin_list->next) + { + counter++; + begin_list = begin_list->next; + } + return (counter); } -void ft_list_reverse_fun(t_list *begin_list) +void ft_list_reverse_fun(t_list *begin_list) { - begin_list = reverse_rec(begin_list); + void *tmp; + unsigned int j; + unsigned int i; + + j = my_size(begin_list); + i = 0; + while (i < j) + { + tmp = my_at(begin_list, i)->data; + my_at(begin_list, i)->data = my_at(begin_list, j)->data; + my_at(begin_list, j)->data = tmp; + i++; + j--; + } } diff --git a/c12/ex16/ft_list.h b/c12/ex16/ft_list.h index 8b736b4..80ec970 100644 --- a/c12/ex16/ft_list.h +++ b/c12/ex16/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:23:48 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/ex16/ft_sorted_list_insert.c b/c12/ex16/ft_sorted_list_insert.c index 2ca345a..f99e567 100644 --- a/c12/ex16/ft_sorted_list_insert.c +++ b/c12/ex16/ft_sorted_list_insert.c @@ -6,11 +6,33 @@ /* 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 */ +/* Updated: 2019/07/23 15:44:40 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ +#include <stdlib.h> +#include "ft_list.h" + void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)()) { + t_list *cursor; + t_list *elem; + cursor = *begin_list; + elem = ft_create_elem(data); + if (cursor == NULL) + { + *begin_list = elem; + return ; + } + if ((*cmp)(elem->data, cursor->data) < 0) + { + elem->next = cursor; + *begin_list = elem; + return ; + } + while (cursor->next && (*cmp)(elem->data, cursor->next->data) > 0) + cursor = cursor->next; + elem->next = cursor->next; + cursor->next = elem; } diff --git a/c12/ex17/ft_list.h b/c12/ex17/ft_list.h index ef3a012..bb1af2d 100644 --- a/c12/ex17/ft_list.h +++ b/c12/ex17/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:25:54 by cacharle ### ########.fr */ +/* Updated: 2019/07/23 15:23:07 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIST_H -#define FT_LIST_H +# define FT_LIST_H typedef struct s_list { diff --git a/c12/ex17/ft_sorted_list_merge.c b/c12/ex17/ft_sorted_list_merge.c index e69de29..fd19f36 100644 --- a/c12/ex17/ft_sorted_list_merge.c +++ b/c12/ex17/ft_sorted_list_merge.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sorted_list_merge.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/22 08:13:44 by cacharle #+# #+# */ +/* Updated: 2019/07/23 16:09:19 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "ft_list.h" + +static void sorted_list_insert(t_list **begin_list, t_list *elem, int (*cmp)()) +{ + t_list *cursor; + + cursor = *begin_list; + if (cursor == NULL) + { + *begin_list = elem; + return ; + } + if ((*cmp)(elem->data, cursor->data) < 0) + { + elem->next = cursor; + *begin_list = elem; + return ; + } + while (cursor->next && (*cmp)(elem->data, cursor->next->data) > 0) + cursor = cursor->next; + elem->next = cursor->next; + cursor->next = elem; +} + +void ft_sorted_list_merge(t_list **begin_list1, t_list *begin_list2, + int (*cmp)()) +{ + while (begin_list2) + { + printf("%d\n", *(int*)begin_list2->data); + begin_list2 = begin_list2->next; + sorted_list_insert(begin_list1, begin_list2, cmp); + } +} @@ -9,18 +9,34 @@ #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"*/ +#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 "ex17/ft_sorted_list_merge.c" +void print_list(t_list *list) +{ + while (list) + { + printf("%d", *(int*)list->data); + if (list->next != NULL) + printf(", "); + list = list->next; + } + printf("\n"); +} + +void each(void *data); +int forcmp(void *data_ref, void* data); +int sortcmp(void *data, void *data_ref); void ft_free(void *data); +void idontdoshit(void *d); int main() { @@ -38,26 +54,33 @@ int main() 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); + ft_list_push_front(&list, &c); + print_list(list); + ft_list_push_front(&list, &d); + print_list(list); - printf("\n--------------\n"); + printf("--------------size\n"); printf("size %d\n", ft_list_size(list)); + ft_list_push_front(&list, &d); ft_list_push_front(&list, &c); - printf("size %d", ft_list_size(list)); + ft_list_push_front(&list, &d); + print_list(list); + printf("size %d\n", ft_list_size(list)); - printf("\n--------------\n"); + printf("--------------last\n"); printf("last %d", *(int*)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); + printf("\n--------------pushback\n"); + print_list(list); + ft_list_push_back(&list, &g); + print_list(list); t_list *empty = NULL; ft_list_push_back(&empty, &e); - printf("empty last %d\n", *(int*)ft_list_last(empty)->data); + print_list(empty); + ft_list_push_back(&empty, &f); + print_list(empty); - printf("\n--------------\n"); + printf("--------------strs\n"); char **strs = malloc(sizeof(char*) * 4); strs[0] = malloc(sizeof(char) * 32); strs[1] = malloc(sizeof(char) * 32); @@ -71,22 +94,104 @@ int main() for (; list_strs; list_strs = list_strs->next) printf("%s | ", (char*)list_strs->data); - /*ft_list_clear(list_strs, &ft_free);*/ + ft_list_clear(list_strs, &ft_free); - printf("\n--------------\n"); + printf("\n--------------at\n"); printf("%d\n", *(int*)(ft_list_at(list, 0)->data)); - printf("%f\n", *(double*)(ft_list_at(list, 1)->data)); - printf("%s\n", (char*)ft_list_at(list, 2)); + printf("%d\n", *(int*)(ft_list_at(list, 7)->data)); + printf("%s\n", (char*)(ft_list_at(list, 8))); + printf("%s\n", (char*)(ft_list_at(list, 10))); - printf("\n--------------\n"); - // reverse + printf("--------------reverse\n"); + print_list(list); + ft_list_reverse(&list); + print_list(list); + print_list(empty); + ft_list_reverse(&empty); + print_list(empty); + + printf("--------------foreach\n"); + ft_list_foreach(list, &each); + + printf("\n--------------foreachif\n"); + ft_list_foreach_if(list, &each, &d, &forcmp); printf("\n--------------\n"); + t_list *found = ft_list_find(list, &d, &forcmp); + print_list(found); + + printf("\n--------------removeif\n"); + print_list(list); + ft_list_remove_if(&list, &d, &forcmp, &idontdoshit); + print_list(list); + + printf("--------------merge\n"); + print_list(list); + ft_list_merge(&list, empty); + print_list(list); + + printf("--------------sort\n"); + print_list(list); + ft_list_sort(&list, &sortcmp); + print_list(list); + printf("--------------revfun\n"); + ft_list_push_front(&list, &b); + ft_list_push_front(&list, &b); + ft_list_push_front(&list, &b); + print_list(list); + ft_list_reverse_fun(list); + print_list(list); + + printf("--------------sortinsert\n"); + int low = 0; + int big = 8; + print_list(list); + ft_sorted_list_insert(&list, &c, &sortcmp); + print_list(list); + ft_sorted_list_insert(&list, &d, &sortcmp); + print_list(list); + ft_sorted_list_insert(&list, &e, &sortcmp); + print_list(list); + ft_sorted_list_insert(&list, &big, &sortcmp); + print_list(list); + ft_sorted_list_insert(&list, &low, &sortcmp); + print_list(list); + + printf("--------------sortmerge\n"); + print_list(empty); + ft_sorted_list_merge(&empty, list, &sortcmp); + print_list(empty); +} + +void each(void *data) +{ + printf("%d ", *(int*)data * 10); +} + +int forcmp(void *data_ref, void* data) +{ + if (*(int*)data_ref == *(int*)data) + return (0); + return (1); +} +int sortcmp(void *data, void *data_ref) +{ + if (*(int*)data < *(int*)data_ref) + return (-1); + else if (*(int*)data > *(int*)data_ref) + return (1); + else + return (0); } void ft_free(void *data) { free((char*)data); } + +void idontdoshit(void *d) +{ + (void)d; +} diff --git a/c13/ex00/btree_create_node.c b/c13/ex00/btree_create_node.c index e69de29..d87b958 100644 --- a/c13/ex00/btree_create_node.c +++ b/c13/ex00/btree_create_node.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/21 18:25:39 by cacharle #+# #+# */ +/* Updated: 2019/07/23 20:40:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "ft_btree.h" + +t_btree *btree_create_node(void *item) +{ + t_btree *node; + + node = (t_btree*)malloc(sizeof(t_btree)); + if (node == NULL) + return (NULL); + node->left = 0; + node->right = 0; + node->item = item; + return (node); +} diff --git a/c13/ex00/ft_btree.h b/c13/ex00/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex00/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ex01/btree_apply_prefix.c b/c13/ex01/btree_apply_prefix.c index e69de29..530d698 100644 --- a/c13/ex01/btree_apply_prefix.c +++ b/c13/ex01/btree_apply_prefix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_infix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/21 18:28:07 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:37:15 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)) +{ + if (root == NULL) + return ; + (*applyf)(root->item); + btree_apply_prefix(root->left); + btree_apply_prefix(root->right); +} diff --git a/c13/ex01/ft_btree.h b/c13/ex01/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex01/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ex02/btree_apply_infix.c b/c13/ex02/btree_apply_infix.c index e69de29..3ff3278 100644 --- a/c13/ex02/btree_apply_infix.c +++ b/c13/ex02/btree_apply_infix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_infix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/21 18:28:07 by cacharle #+# #+# */ +/* Updated: 2019/07/23 21:09:53 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_infix(t_btree *root, void (*applyf)(void *)) +{ + if (root == NULL) + return ; + btree_apply_infix(root->left); + (*applyf)(root->item); + btree_apply_infix(root->right); +} diff --git a/c13/ex02/ft_btree.h b/c13/ex02/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex02/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ex03/btree_apply_suffix.c b/c13/ex03/btree_apply_suffix.c index e69de29..6d5c3b2 100644 --- a/c13/ex03/btree_apply_suffix.c +++ b/c13/ex03/btree_apply_suffix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_suffix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/21 18:37:33 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:38:10 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)) +{ + if (root == NULL) + return ; + btree_apply_suffix(root->left); + btree_apply_suffix(root->right); + (*applyf)(root->item); +} diff --git a/c13/ex03/ft_btree.h b/c13/ex03/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex03/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ex04/btree_insert_data.c b/c13/ex04/btree_insert_data.c index e69de29..0999cab 100644 --- a/c13/ex04/btree_insert_data.c +++ b/c13/ex04/btree_insert_data.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_insert_data.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/21 18:43:18 by cacharle #+# #+# */ +/* Updated: 2019/07/23 20:49:48 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "ft_btree.h" + +// this is half shit +void btree_insert_data(t_btree **root, void *item, int (*cmpf)(void *, void *)) +{ + if (*root == NULL) + *root = btree_create_elem(item); + if ((*cmpf)((*root)->item, item) < 0) + btree_insert_root(&(*root)->left, item, cmpf); + else if ((*cmpf)((*root)->item, item) > 0) + btree_insert_root(&(*root)->right, item, cmpf); +} diff --git a/c13/ex04/ft_btree.h b/c13/ex04/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex04/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ex05/btree_search_item.c b/c13/ex05/btree_search_item.c index e69de29..b5d7114 100644 --- a/c13/ex05/btree_search_item.c +++ b/c13/ex05/btree_search_item.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_search_item.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/23 20:49:54 by cacharle #+# #+# */ +/* Updated: 2019/07/23 21:09:10 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void *btree_search_item(t_btree *root, void *data_ref, int (*cmpf)(void *, void *)) +{ + +} diff --git a/c13/ex05/ft_btree.h b/c13/ex05/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex05/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ex06/ft_btree.h b/c13/ex06/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex06/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ex07/ft_btree.h b/c13/ex07/ft_btree.h new file mode 100644 index 0000000..3af177e --- /dev/null +++ b/c13/ex07/ft_btree.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +} t_btree; + +#endif diff --git a/c13/ft_btree.h b/c13/ft_btree.h index a05beeb..3af177e 100644 --- a/c13/ft_btree.h +++ b/c13/ft_btree.h @@ -6,11 +6,12 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/17 19:29:12 by cacharle #+# #+# */ -/* Updated: 2019/07/17 19:29:37 by cacharle ### ########.fr */ +/* Updated: 2019/07/21 18:19:33 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_BTREE_H +# define FT_BTREE_H typedef struct s_btree { @@ -18,3 +19,5 @@ typedef struct s_btree struct s_btree *right; void *item; } t_btree; + +#endif |
