From 8b6e91bdb56bc01a588718472546f2a88e750b48 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 19 Jul 2019 07:04:04 +0200 Subject: c10 done?, c11 moulinetted (ex04, ex06 need correction) --- c11/ex04/ft_is_sort.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'c11/ex04') diff --git a/c11/ex04/ft_is_sort.c b/c11/ex04/ft_is_sort.c index 7afed9c..84d4fe0 100644 --- a/c11/ex04/ft_is_sort.c +++ b/c11/ex04/ft_is_sort.c @@ -6,13 +6,12 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 21:39:43 by cacharle #+# #+# */ -/* Updated: 2019/07/17 16:34:13 by cacharle ### ########.fr */ +/* Updated: 2019/07/18 21:19:29 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -int ft_is_sort(int *tab, int length, int(*f)(int, int)) +static is_sort_asc(int *tab, int length, int (*f)(int, int)) { - int i; i = 0; @@ -24,3 +23,22 @@ int ft_is_sort(int *tab, int length, int(*f)(int, int)) } return (1); } + +static is_sort_dsc(int *tab, int length, int (*f)(int, int)) +{ + int i; + + i = 0; + while (i < length - 1) + { + if ((*f)(tab[i], tab[i + 1]) < 0) + return (0); + i++; + } + return (1); +} + +int ft_is_sort(int *tab, int length, int (*f)(int, int)) +{ + return (is_sort_dsc(tab, length, f) || is_sort_asc(tab, length, f)); +} -- cgit