diff --git a/Makefile b/Makefile index f0391c3..766f7cc 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/04/07 12:47:06 by tmaze #+# #+# # -# Updated: 2018/10/01 12:35:21 by tmaze ### ########.fr # +# Updated: 2018/10/02 16:05:34 by tmaze ### ########.fr # # # #******************************************************************************# CC = gcc -CCFLAGS = -Wall -Werror -Wextra +CCFLAGS = -Wall -Werror -Wextra -g CCSTD = NAME = libft.a diff --git a/ft_lstaddsort.c b/ft_lstaddsort.c index 0698da1..c8aef4a 100644 --- a/ft_lstaddsort.c +++ b/ft_lstaddsort.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/10/01 11:57:25 by tmaze #+# #+# */ -/* Updated: 2018/10/01 13:10:02 by tmaze ### ########.fr */ +/* Updated: 2018/10/02 16:43:09 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,13 +15,17 @@ void ft_lstaddsort(t_list **lst, t_list *new, int (*f)(void *c1, void *c2), int rev) { - t_list *sorted; + t_list **sort; - sorted = *lst; - if (rev) - ft_putstr("rev\n"); - while (sorted && (((*f)(sorted->content, new->content) >= 0 && rev)) - || (*f)(sorted->content, new->content) <= 0) - sorted = sorted->next; - ft_lstadd(lst, new); + sort = lst; + if (*lst == NULL || (!rev && (*f)((*lst)->content, new->content) > 0) + || (rev && (*f)((*lst)->content, new->content) < 0)) + ft_lstadd(lst, new); + else + { + while ((*sort) && ((rev && (*f)((*sort)->content, new->content) >= 0) + || (!rev && (*f)((*sort)->content, new->content) <= 0))) + sort = &(*sort)->next; + ft_lstadd(&(*sort), new); + } }