42_push_swap/ft_is_sorted.c
2022-11-30 13:21:32 +01:00

35 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_sorted.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 14:41:08 by cchauvet #+# #+# */
/* Updated: 2022/11/29 19:02:34 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
int ft_is_sorted(int *in)
{
unsigned int *tab;
unsigned int prev;
unsigned int i;
int shift;
shift = ft_bit_finder_right(ft_get_bit_min(in), 1) - 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);
}