42_push_swap/ft_radix.c
Camille Chauvet 3fc423de4a presque
2022-12-06 17:35:45 +01:00

37 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_radix.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/15 18:16:31 by cchauvet #+# #+# */
/* Updated: 2022/12/06 17:22:52 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b)
{
unsigned int i;
unsigned int y;
i = 0;
while (!ft_is_sorted(tab_a) && i < sizeof(unsigned int) * 8)
{
y = ft_tablen(tab_a);
while (0 < y && (!ft_is_sorted(tab_a) && !ft_tablen(tab_b)))
{
if (((tab_a[ft_tablen(tab_a) - 1] >> i) & 1) == 1)
ft_pb(tab_a, tab_b);
else
ft_ra(tab_a);
y--;
}
while (tab_b[0] != STOP_VALUE)
ft_pa(tab_a, tab_b);
i++;
}
}