diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-19 07:04:04 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-19 07:04:04 +0200 |
| commit | 8b6e91bdb56bc01a588718472546f2a88e750b48 (patch) | |
| tree | 654ba9e8216c688bb3d6a2e5d67526ae8ec4b874 /c11/ex04 | |
| parent | 880102ae9358db130ef67cc9a7177a1e1de76875 (diff) | |
| download | piscine-8b6e91bdb56bc01a588718472546f2a88e750b48.tar.gz piscine-8b6e91bdb56bc01a588718472546f2a88e750b48.tar.bz2 piscine-8b6e91bdb56bc01a588718472546f2a88e750b48.zip | |
c10 done?, c11 moulinetted (ex04, ex06 need correction)
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)); +} |
