From 3280ed74b455106e9aa7a9f6defb1d6cb2d0365a Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sat, 24 Sep 2016 17:46:39 +0200 Subject: [PATCH] lst merge, reverse --- libft/includes/libft.h | 5 +++++ libft/src/ft_printf/ft_parse.c | 2 +- libft/src/ft_printf/ft_printf.c | 3 ++- libft/src/lst/ft_lst_merge.c | 28 ++++++++++++++++++++++++++++ libft/src/lst/ft_lst_reverse.c | 29 +++++++++++++++++++++++++++++ libft/src/lst/ft_lsteadd.c | 1 + libft/src/lst/ft_lstmap.c | 10 ++-------- libft/src/strl/ft_strlsort.c | 21 +++++++++++++++++++++ 8 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 libft/src/lst/ft_lst_merge.c create mode 100644 libft/src/lst/ft_lst_reverse.c create mode 100644 libft/src/strl/ft_strlsort.c diff --git a/libft/includes/libft.h b/libft/includes/libft.h index 0d7553b6..309740fd 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -1,5 +1,6 @@ #ifndef LIBFT_H #define LIBFT_H +#include "libftprintf.h" # include # include # include @@ -97,6 +98,8 @@ t_list *ft_lst_filter(t_list *lst, void const *data_ref, t_list *(*f)(t_list *el t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)()); t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)()); t_list *ft_lstpop(t_list **lst); +void ft_lst_merge(t_list **begin_list1, t_list *begin_list2); +void ft_lst_reverse(t_list **begin_list); int ft_diff(void *a, void *b); char *ft_strrev(char *str); @@ -105,4 +108,6 @@ char *ft_itoa_base(int nbr, char *base, char *flags); char *ft_lltoa_base(long long nbr, char *base, char *flags); char *ft_ulltoa_base(unsigned long long nbr, char *base); char *ft_uitoa_base(unsigned int nbr, char *base); + +void ft_strlsort(char **list, int size, int (*cmp)()); #endif diff --git a/libft/src/ft_printf/ft_parse.c b/libft/src/ft_printf/ft_parse.c index 735f7fa4..38e31613 100644 --- a/libft/src/ft_printf/ft_parse.c +++ b/libft/src/ft_printf/ft_parse.c @@ -90,6 +90,6 @@ t_fmt *ft_parse(char **format) ft_fmt_simplify(fmt); fmt->valid = ft_fmt_validate_conversion(fmt) ? 0 : 1; - ft_fmt_print(fmt); + /* ft_fmt_print(fmt); */ return (fmt); } diff --git a/libft/src/ft_printf/ft_printf.c b/libft/src/ft_printf/ft_printf.c index 733338ee..23c21cb4 100644 --- a/libft/src/ft_printf/ft_printf.c +++ b/libft/src/ft_printf/ft_printf.c @@ -21,7 +21,8 @@ int ft_printf(const char *format, ...) va_start(ap1, format); str = ft_strdup(format); - ft_putendl(format); + ft_bzero(final, 1000); + /* ft_putendl(format); */ while (*str) { if (*str == '%') diff --git a/libft/src/lst/ft_lst_merge.c b/libft/src/lst/ft_lst_merge.c new file mode 100644 index 00000000..4860f669 --- /dev/null +++ b/libft/src/lst/ft_lst_merge.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_merge.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/14 13:50:32 by jhalford #+# #+# */ +/* Updated: 2016/08/16 20:49:02 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lst_merge(t_list **begin_list1, t_list *begin_list2) +{ + t_list *list_ptr; + + if (*begin_list1) + { + list_ptr = *begin_list1; + while (list_ptr->next) + list_ptr = list_ptr->next; + list_ptr->next = begin_list2; + } + else + *begin_list1 = begin_list2; +} diff --git a/libft/src/lst/ft_lst_reverse.c b/libft/src/lst/ft_lst_reverse.c new file mode 100644 index 00000000..1445df17 --- /dev/null +++ b/libft/src/lst/ft_lst_reverse.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_reverse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/14 13:20:13 by jhalford #+# #+# */ +/* Updated: 2016/08/16 22:34:13 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lst_reverse(t_list **begin_list) +{ + t_list *new_start; + t_list *tmp; + + new_start = NULL; + while (*begin_list) + { + tmp = (*begin_list)->next; + (*begin_list)->next = new_start; + new_start = *begin_list; + *begin_list = tmp; + } + *begin_list = new_start; +} diff --git a/libft/src/lst/ft_lsteadd.c b/libft/src/lst/ft_lsteadd.c index 3b9e391f..9456158d 100644 --- a/libft/src/lst/ft_lsteadd.c +++ b/libft/src/lst/ft_lsteadd.c @@ -5,6 +5,7 @@ void ft_lsteadd(t_list **alst, t_list *new) t_list *lst; lst = *alst; + new->next = NULL; if (lst) { while (lst->next) diff --git a/libft/src/lst/ft_lstmap.c b/libft/src/lst/ft_lstmap.c index 9c8a3edd..5d30a227 100644 --- a/libft/src/lst/ft_lstmap.c +++ b/libft/src/lst/ft_lstmap.c @@ -9,16 +9,10 @@ t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) while (lst) { elem = (*f)(lst); - /* printf("size=%zu\n", elem->content_size); */ - /* printf("content=%i\n", *(int*)elem->content); */ - /* fflush(stdout); */ - elem = ft_lstnew(elem->content, elem->content_size); - /* printf("size=%zu\n", elem->content_size); */ - /* printf("content=%i\n", *(int*)elem->content); */ - /* fflush(stdout); */ + if (elem) + elem = ft_lstnew(elem->content, elem->content_size); ft_lsteadd(&out, elem); lst = lst->next; } - /* ft_lst_print(out, &ft_putnbr); */ return (out); } diff --git a/libft/src/strl/ft_strlsort.c b/libft/src/strl/ft_strlsort.c new file mode 100644 index 00000000..767b3edf --- /dev/null +++ b/libft/src/strl/ft_strlsort.c @@ -0,0 +1,21 @@ +#include "libft.h" + +void ft_strlsort(char **list, int size, int (*cmp)()) +{ + int i; + char *tmp; + + i = 0; + while (i < size - 1) + { + if ((*cmp)(list[i], list[i + 1]) > 0) + { + tmp = list[i]; + list[i] = list[i + 1]; + list[i + 1] = tmp; + i = 0; + } + else + i++; + } +}