42_push_swap/ft_radix.c
2022-12-09 15:22:02 +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/07 14:33:00 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))
{
y = ft_tablen(tab_a);
while (0 < y && !(ft_is_sorted(tab_a) && !ft_tablen(tab_b)))
{
if (((tab_a[0] >> i) & 1) == 0)
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++;
}
}