diff options
Diffstat (limited to 'c11/ex04')
| -rw-r--r-- | c11/ex04/ft_is_sort.c | 24 |
1 files changed, 21 insertions, 3 deletions
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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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)); +} |
