debug ft_lstaddsort & lstsort

This commit is contained in:
Tanguy MAZE 2018-10-02 16:49:59 +02:00
parent 405c9b9717
commit b1db252441
2 changed files with 15 additions and 11 deletions

View File

@ -6,12 +6,12 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
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);
}
}