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-01 11:15:17 -05:00
|
|
|
/* Updated: 2022/12/01 17:13:35 by cchauvet ### ########.fr */
|
2022-11-23 15:44:27 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "pushswap.h"
|
|
|
|
|
2022-12-01 11:15:17 -05:00
|
|
|
void ft_radix_sort(unsigned *tab_a, unsigned *tab_b)
|
2022-11-23 15:44:27 -05:00
|
|
|
{
|
2022-11-30 14:11:35 -05:00
|
|
|
int tab_index;
|
|
|
|
int loop_index;
|
2022-11-23 15:44:27 -05:00
|
|
|
|
2022-11-30 07:21:32 -05:00
|
|
|
while (!ft_is_sorted(tab_a))
|
2022-11-23 15:44:27 -05:00
|
|
|
{
|
2022-11-30 14:11:35 -05:00
|
|
|
tab_index = ft_tablen(tab_a) - 1;
|
|
|
|
loop_index = tab_index;
|
2022-12-01 11:15:17 -05:00
|
|
|
while (loop_index >= 0 && !ft_is_sorted(tab_a))
|
2022-11-23 15:44:27 -05:00
|
|
|
{
|
2022-12-01 11:15:17 -05:00
|
|
|
if (tab_a[tab_index] % 2 == 1)
|
2022-11-30 14:11:35 -05:00
|
|
|
{
|
2022-11-30 07:21:32 -05:00
|
|
|
ft_pb(tab_a, tab_b);
|
2022-11-30 14:11:35 -05:00
|
|
|
tab_index--;
|
|
|
|
}
|
2022-11-23 15:44:27 -05:00
|
|
|
else
|
2022-11-30 07:21:32 -05:00
|
|
|
ft_ra(tab_a);
|
2022-11-30 14:11:35 -05:00
|
|
|
loop_index--;
|
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-11-30 14:11:35 -05:00
|
|
|
tab_index = ft_tablen(tab_a);
|
|
|
|
while (--tab_index >= 0 && !ft_is_sorted(tab_a))
|
2022-12-01 11:15:17 -05:00
|
|
|
tab_a[tab_index] = tab_a[tab_index] >> 1;
|
2022-11-23 15:44:27 -05:00
|
|
|
}
|
2022-11-30 14:11:35 -05:00
|
|
|
free(tab_a);
|
|
|
|
free(tab_b);
|
2022-11-23 15:44:27 -05:00
|
|
|
}
|