42_push_swap/ft_radix.c

37 lines
1.3 KiB
C
Raw Permalink Normal View History

2022-11-23 15:44:27 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_radix.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/15 18:16:31 by cchauvet #+# #+# */
2022-12-09 09:22:02 -05:00
/* Updated: 2022/12/07 14:33:00 by cchauvet ### ########.fr */
2022-11-23 15:44:27 -05:00
/* */
/* ************************************************************************** */
#include "pushswap.h"
2022-12-06 11:35:45 -05:00
void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b)
2022-11-23 15:44:27 -05:00
{
2022-12-06 11:35:45 -05:00
unsigned int i;
unsigned int y;
2022-11-23 15:44:27 -05:00
2022-12-06 11:35:45 -05:00
i = 0;
2022-12-09 09:22:02 -05:00
while (!ft_is_sorted(tab_a))
2022-11-23 15:44:27 -05:00
{
2022-12-06 11:35:45 -05:00
y = ft_tablen(tab_a);
2022-12-07 08:19:16 -05:00
while (0 < y && !(ft_is_sorted(tab_a) && !ft_tablen(tab_b)))
2022-11-23 15:44:27 -05:00
{
2022-12-07 08:19:16 -05:00
if (((tab_a[0] >> i) & 1) == 0)
2022-11-30 07:21:32 -05:00
ft_pb(tab_a, tab_b);
2022-11-23 15:44:27 -05:00
else
2022-11-30 07:21:32 -05:00
ft_ra(tab_a);
2022-12-06 11:35:45 -05:00
y--;
2022-11-23 15:44:27 -05:00
}
2022-12-01 11:15:17 -05:00
while (tab_b[0] != STOP_VALUE)
2022-11-30 07:21:32 -05:00
ft_pa(tab_a, tab_b);
2022-12-06 11:35:45 -05:00
i++;
2022-11-23 15:44:27 -05:00
}
}