diff --git a/Makefile b/Makefile index 193453d..8acf246 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,11 @@ # By: cchauvet > shift != (prev >> shift) - 1) + if (tab[1] != 0) return (0); - prev = tab[i]; i++; } return (1); } - -int ft_is_sorted(int *in) -{ - return (ft_bit_finder_right(ft_get_bit_min(in), 1) == 31); -} diff --git a/ft_is_sorted.o b/ft_is_sorted.o index 3168522..19ec7e1 100644 Binary files a/ft_is_sorted.o and b/ft_is_sorted.o differ diff --git a/ft_p.c b/ft_p.c index 507dfe2..afba712 100644 --- a/ft_p.c +++ b/ft_p.c @@ -6,13 +6,13 @@ /* By: cchauvet 0 && !ft_is_sorted(tab_a)) + while (loop_index >= 0 && !ft_is_sorted(tab_a)) { - if (tab_a[tab_index] >> shift & 1) + if (tab_a[tab_index] % 2 == 1) { ft_pb(tab_a, tab_b); tab_index--; @@ -34,11 +32,11 @@ void ft_radix_sort(int *tab_a, int *tab_b) ft_ra(tab_a); loop_index--; } - while (tab_b[0] != -1) + 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; + tab_a[tab_index] = tab_a[tab_index] >> 1; } free(tab_a); free(tab_b); diff --git a/ft_radix.o b/ft_radix.o index 06bd29d..084b841 100644 Binary files a/ft_radix.o and b/ft_radix.o differ diff --git a/ft_sort.c b/ft_sort.c index b7dc1fd..e3544be 100644 --- a/ft_sort.c +++ b/ft_sort.c @@ -6,65 +6,60 @@ /* By: cchauvet # include # include +# define STOP_VALUE 4294967295 int ft_isnum(char *str); int ft_atoi(char *str); @@ -27,19 +28,15 @@ int ft_get_max_index(int *tab, int len); int ft_get_min_index(int *tab, int len); int ft_get_min_index(int *tab, int len); -int ft_tablen(int *tab); -int ft_is_sorted(int *in); +int ft_tablen(unsigned int *tab); +int ft_is_sorted(unsigned int *in); -int ft_bit_finder_left(int big, int tofind); -int ft_bit_finder_right(int big, int tofind); -int ft_get_bit_max(int *tab); -int ft_get_bit_min(int *tab); -void ft_radix_sort(int *tab_a, int *tab_b); +void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b); -void ft_swap(int *a, int *b); -void ft_pa(int *tab_a, int *tab_b); -void ft_pb(int *tab_a, int *tab_b); -void ft_ra(int *tab_a); -void ft_rb(int *tab_b); +void ft_swap(unsigned int *a, unsigned int *b); +void ft_pa(unsigned int *tab_a, unsigned int *tab_b); +void ft_pb(unsigned int *tab_a, unsigned int *tab_b); +void ft_ra(unsigned int *tab_a); +void ft_rb(unsigned int *tab_b); #endif