diff options
| -rw-r--r-- | include/libft_lst.h | 8 | ||||
| -rw-r--r-- | src/ctype/ft_isascii.c | 6 | ||||
| -rw-r--r-- | src/ht/ft_htnew.c | 6 | ||||
| -rw-r--r-- | src/lst/ft_lstsort.c | 40 | ||||
| -rw-r--r-- | src/lst/ft_lstsorted_merge.c | 36 |
5 files changed, 86 insertions, 10 deletions
diff --git a/include/libft_lst.h b/include/libft_lst.h index 2a420c4..d092e59 100644 --- a/include/libft_lst.h +++ b/include/libft_lst.h @@ -6,13 +6,14 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:36:39 by cacharle #+# #+# */ -/* Updated: 2020/01/31 10:36:41 by cacharle ### ########.fr */ +/* Updated: 2020/02/10 02:12:26 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIBFT_LST_H # define LIBFT_LST_H +# include <stdlib.h> # include "libft_types.h" typedef struct s_ftlst @@ -30,7 +31,7 @@ void ft_lstdelone(t_ftlst *lst, void (*del)(void *)); void ft_lstclear(t_ftlst **lst, void (*del)(void *)); void ft_lstiter(t_ftlst *lst, void (*f)(void *)); t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), - void (*del)(void *)); + void (*del)(void *)); void ft_lstpop_front(t_ftlst **lst, void (*del)(void *)); t_ftlst *ft_lstreverse_ret(t_ftlst *lst); void ft_lstreverse(t_ftlst **lst); @@ -39,5 +40,8 @@ void ft_lstremove_if(t_ftlst **lst, void (*del)(void *content)); t_ftlst *ft_lstbsearch(t_ftlst *lst, t_ftbool (*equal)(void *ref, void *content), void *ref); +void ft_lstsort(t_ftlst **begin_list, int (*cmp)(void *, void*)); +t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, + int (*cmp)(void *, void *)); #endif diff --git a/src/ctype/ft_isascii.c b/src/ctype/ft_isascii.c index 51dcd1c..376ee54 100644 --- a/src/ctype/ft_isascii.c +++ b/src/ctype/ft_isascii.c @@ -6,13 +6,11 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 09:54:30 by cacharle #+# #+# */ -/* Updated: 2019/10/20 13:03:23 by cacharle ### ########.fr */ +/* Updated: 2020/02/10 02:14:40 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -#define MAX_CHAR ((1 << 7) - 1) - int ft_isascii(int c) { - return (c >= 0 && c <= MAX_CHAR); + return (c >= 0 && c <= 255); } diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c index 950a4fe..d98a724 100644 --- a/src/ht/ft_htnew.c +++ b/src/ht/ft_htnew.c @@ -6,20 +6,18 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:19:16 by cacharle #+# #+# */ -/* Updated: 2020/01/31 10:41:57 by cacharle ### ########.fr */ +/* Updated: 2020/02/10 02:16:20 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "libft_ht.h" -#define FT_HT_MAX_SIZE (1 << 14) - t_ftht *ft_htnew(t_ftsize size) { t_ftht *ht; - if (size == 0 || size > FT_HT_MAX_SIZE) + if (size == 0) return (NULL); if ((ht = (t_ftht*)malloc(sizeof(t_ftht))) == NULL) return (NULL); diff --git a/src/lst/ft_lstsort.c b/src/lst/ft_lstsort.c new file mode 100644 index 0000000..883604f --- /dev/null +++ b/src/lst/ft_lstsort.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 01:53:55 by cacharle #+# #+# */ +/* Updated: 2020/02/10 02:09:28 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +void ft_lstsort(t_ftlst **begin_list, int (*cmp)(void *, void*)) +{ + t_ftlst *fast; + t_ftlst *slow; + t_ftlst *middle; + + if (begin_list == NULL || *begin_list == NULL + || (*begin_list)->next == NULL) + return ; + fast = (*begin_list)->next; + slow = *begin_list; + while (fast != NULL) + { + fast = fast->next; + if (fast != NULL) + { + fast = fast->next; + slow = slow->next; + } + } + middle = slow->next; + slow->next = NULL; + ft_lstsort(begin_list, cmp); + ft_lstsort(&middle, cmp); + *begin_list = ft_lstsorted_merge(*begin_list, middle, cmp); +} diff --git a/src/lst/ft_lstsorted_merge.c b/src/lst/ft_lstsorted_merge.c new file mode 100644 index 0000000..c3d0391 --- /dev/null +++ b/src/lst/ft_lstsorted_merge.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsorted_merge.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 01:58:52 by cacharle #+# #+# */ +/* Updated: 2020/02/10 02:13:37 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, + int (*cmp)(void *, void *)) +{ + t_ftlst *merged; + + merged = NULL; + if (l1 == NULL) + return (l2); + if (l2 == NULL) + return (l1); + if (cmp(l1->content, l2->content) < 0) + { + merged = l1; + merged->next = ft_lstsorted_merge(l1->next, l2, cmp); + } + else + { + merged = l2; + merged->next = ft_lstsorted_merge(l1, l2->next, cmp); + } + return (merged); +} |
