42_push_swap/ft_is_sorted.c
Camille Chauvet 7ccda635a2 sa marche pa
2022-11-30 20:11:35 +01:00

40 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_sorted.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 14:41:08 by cchauvet #+# #+# */
/* Updated: 2022/11/30 20:09:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
int ft_is_sortee(int *in)
{
unsigned int *tab;
unsigned int prev;
unsigned int i;
int shift;
shift = ft_bit_finder_right(ft_get_bit_min(in), 1);
tab = (unsigned int *) in;
prev = tab[0];
i = 1;
while (in[i] != -1)
{
if (tab[i] >> shift != (prev >> shift) - 1)
return (0);
prev = tab[i];
i++;
}
return (1);
}
int ft_is_sorted(int *in)
{
return (ft_bit_finder_right(ft_get_bit_min(in), 1) == 31);
}