sa marche pa
This commit is contained in:
parent
36a1e52502
commit
7ccda635a2
BIN
checker_linux
Executable file
BIN
checker_linux
Executable file
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/23 17:31:10 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/29 15:06:00 by cchauvet ### ########.fr */
|
||||
/* Updated: 2022/11/30 20:07:51 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,10 +25,5 @@ int ft_bit_finder_left(int big, int tofind)
|
||||
|
||||
int ft_bit_finder_right(int big, int tofind)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i != ((int) sizeof(int) * 8 - 1) && ((big << i) & 1) != tofind)
|
||||
i++;
|
||||
return (i);
|
||||
return ((int) sizeof(int) * 8 - 1 - ft_bit_finder_left(big, tofind));
|
||||
}
|
||||
|
BIN
ft_bit_finder.o
BIN
ft_bit_finder.o
Binary file not shown.
@ -6,20 +6,20 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/29 14:41:08 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/29 19:02:34 by cchauvet ### ########.fr */
|
||||
/* Updated: 2022/11/30 20:09:57 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "pushswap.h"
|
||||
|
||||
int ft_is_sorted(int *in)
|
||||
int ft_is_sortee(int *in)
|
||||
{
|
||||
unsigned int *tab;
|
||||
unsigned int prev;
|
||||
unsigned int i;
|
||||
int shift;
|
||||
|
||||
shift = ft_bit_finder_right(ft_get_bit_min(in), 1) - 1;
|
||||
shift = ft_bit_finder_right(ft_get_bit_min(in), 1);
|
||||
tab = (unsigned int *) in;
|
||||
prev = tab[0];
|
||||
i = 1;
|
||||
@ -32,3 +32,8 @@ int ft_is_sorted(int *in)
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_is_sorted(int *in)
|
||||
{
|
||||
return (ft_bit_finder_right(ft_get_bit_min(in), 1) == 31);
|
||||
}
|
||||
|
BIN
ft_is_sorted.o
BIN
ft_is_sorted.o
Binary file not shown.
26
ft_radix.c
26
ft_radix.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/15 18:16:31 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/30 13:19:13 by cchauvet ### ########.fr */
|
||||
/* Updated: 2022/11/30 20:06:39 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,22 +14,32 @@
|
||||
|
||||
void ft_radix_sort(int *tab_a, int *tab_b)
|
||||
{
|
||||
int i;
|
||||
int tab_index;
|
||||
int loop_index;
|
||||
int shift;
|
||||
|
||||
while (!ft_is_sorted(tab_a))
|
||||
{
|
||||
i = ft_tablen(tab_a);
|
||||
while (--i >= 0 && !ft_is_sorted(tab_a))
|
||||
tab_index = ft_tablen(tab_a) - 1;
|
||||
loop_index = tab_index;
|
||||
shift = ft_bit_finder_right(ft_get_bit_min(tab_a), 1);
|
||||
while (loop_index > 0 && !ft_is_sorted(tab_a))
|
||||
{
|
||||
if ((tab_a[i] >> (sizeof(int) * 8 -1) & 1) == 0)
|
||||
if (tab_a[tab_index] >> shift & 1)
|
||||
{
|
||||
ft_pb(tab_a, tab_b);
|
||||
tab_index--;
|
||||
}
|
||||
else
|
||||
ft_ra(tab_a);
|
||||
loop_index--;
|
||||
}
|
||||
while (tab_b[0] != -1)
|
||||
ft_pa(tab_a, tab_b);
|
||||
i = ft_tablen(tab_a);
|
||||
while (--i >= 0 && !ft_is_sorted(tab_a))
|
||||
tab_a[i] = tab_a[i] << 1;
|
||||
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);
|
||||
}
|
||||
|
BIN
ft_radix.o
BIN
ft_radix.o
Binary file not shown.
92
ft_split.c
Normal file
92
ft_split.c
Normal file
@ -0,0 +1,92 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/28 19:23:45 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void *ft_cancel(char **tab, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (tab != NULL)
|
||||
{
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
free(tab[i]);
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static size_t ft_seglen(const char *s, char c)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
len = 0;
|
||||
while (*s != 0)
|
||||
{
|
||||
while (*s == c && *s != 0)
|
||||
s++;
|
||||
if (*s != 0)
|
||||
len++;
|
||||
while (*s != c && *s != 0)
|
||||
s++;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)
|
||||
{
|
||||
size_t tab_index;
|
||||
size_t let_index;
|
||||
size_t start;
|
||||
|
||||
tab_index = 0;
|
||||
let_index = 0;
|
||||
start = 0;
|
||||
if (tab == NULL || s == NULL)
|
||||
return (NULL);
|
||||
while (tab_index < len)
|
||||
{
|
||||
while (s[let_index] == c && s[let_index] != 0)
|
||||
let_index++;
|
||||
start = let_index;
|
||||
while (s[let_index] != c && s[let_index] != 0)
|
||||
let_index++;
|
||||
tab[tab_index] = ft_substr(s, start, let_index - start);
|
||||
if (tab[tab_index] == NULL)
|
||||
return (ft_cancel(tab, tab_index));
|
||||
tab_index++;
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
|
||||
char **ft_split(const char *s, char c)
|
||||
{
|
||||
size_t len;
|
||||
char **tab;
|
||||
|
||||
if (s == NULL)
|
||||
return (NULL);
|
||||
len = ft_seglen(s, c);
|
||||
tab = malloc((len + 1) * sizeof(char *));
|
||||
if (tab == NULL)
|
||||
return (NULL);
|
||||
tab[len] = NULL;
|
||||
if (ft_segsplitter(tab, len, s, c) == NULL)
|
||||
return (NULL);
|
||||
return (tab);
|
||||
}
|
4
main.c
4
main.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/09 17:10:47 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/28 17:57:29 by cchauvet ### ########.fr */
|
||||
/* Updated: 2022/11/30 14:13:09 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,7 +25,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (!ft_isnum(argv[i]))
|
||||
{
|
||||
ft_putstr("Erreur: args doesn't containe only numbers !");
|
||||
write(2, "Error\n", 6);
|
||||
return (1);
|
||||
}
|
||||
tab_a[i - 1] = ft_atoi(argv[i]);
|
||||
|
1
push_swap_tester
Submodule
1
push_swap_tester
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 59628457df966b6a6a12e63cecaa29456d2ed250
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/08 18:19:44 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/29 16:22:26 by cchauvet ### ########.fr */
|
||||
/* Updated: 2022/11/30 13:30:55 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
int ft_isnum(char *str);
|
||||
int ft_atoi(char *str);
|
||||
void ft_putstr(char *str);
|
||||
char **ft_split(const char *s, char c);
|
||||
|
||||
void ft_sort(int *tab, int size);
|
||||
int ft_get_max_index(int *tab, int len);
|
||||
|
Loading…
Reference in New Issue
Block a user