42_push_swap/ft_radix.c

52 lines
1.7 KiB
C
Raw 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-07 08:19:16 -05:00
/* Updated: 2022/12/07 14:18:44 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-12-07 08:19:16 -05:00
unsigned int bit_shift;
int j;
2022-11-23 15:44:27 -05:00
2022-12-07 08:19:16 -05:00
bit_shift = ft_bitlen(ft_get_max(tab_a)) + 1;
2022-12-06 11:35:45 -05:00
i = 0;
2022-12-07 08:19:16 -05:00
while (!ft_is_sorted(tab_a) && i < bit_shift)
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-12-07 08:19:16 -05:00
j = 0;
printf("tab_a:\n");
while (tab_a[j] != STOP_VALUE)
printf("%d\n", tab_a[j++]);
j = 0;
printf("tab_b:\n");
while (tab_b[j] != STOP_VALUE)
printf("%d\n", tab_b[j++]);
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-12-07 08:19:16 -05:00
j = 0;
printf("\n\nROUND[%d]\ntab_a:\n", i);
while (tab_a[j] != STOP_VALUE)
printf("%d\n", tab_a[j++]);
2022-11-23 15:44:27 -05:00
}
}