44 lines
1.5 KiB
C
44 lines
1.5 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_radix.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/11/15 18:16:31 by cchauvet #+# #+# */
|
|
/* Updated: 2022/12/01 17:13:35 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "pushswap.h"
|
|
|
|
void ft_radix_sort(unsigned *tab_a, unsigned *tab_b)
|
|
{
|
|
int tab_index;
|
|
int loop_index;
|
|
|
|
while (!ft_is_sorted(tab_a))
|
|
{
|
|
tab_index = ft_tablen(tab_a) - 1;
|
|
loop_index = tab_index;
|
|
while (loop_index >= 0 && !ft_is_sorted(tab_a))
|
|
{
|
|
if (tab_a[tab_index] % 2 == 1)
|
|
{
|
|
ft_pb(tab_a, tab_b);
|
|
tab_index--;
|
|
}
|
|
else
|
|
ft_ra(tab_a);
|
|
loop_index--;
|
|
}
|
|
while (tab_b[0] != STOP_VALUE)
|
|
ft_pa(tab_a, tab_b);
|
|
tab_index = ft_tablen(tab_a);
|
|
while (--tab_index >= 0 && !ft_is_sorted(tab_a))
|
|
tab_a[tab_index] = tab_a[tab_index] >> 1;
|
|
}
|
|
free(tab_a);
|
|
free(tab_b);
|
|
}
|