sa marche pa

This commit is contained in:
Camille Chauvet 2022-11-30 20:11:35 +01:00
parent 36a1e52502
commit 7ccda635a2
15 changed files with 126 additions and 21 deletions

BIN
a.out

Binary file not shown.

1
check.sh Executable file
View File

@ -0,0 +1 @@
./push_swap $@ | ./checker_linux $@

BIN
checker_linux Executable file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/23 17:31:10 by cchauvet #+# #+# */ /* 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 ft_bit_finder_right(int big, int tofind)
{ {
int i; return ((int) sizeof(int) * 8 - 1 - ft_bit_finder_left(big, tofind));
i = 0;
while (i != ((int) sizeof(int) * 8 - 1) && ((big << i) & 1) != tofind)
i++;
return (i);
} }

Binary file not shown.

View File

@ -6,20 +6,20 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 14:41:08 by cchauvet #+# #+# */ /* 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" #include "pushswap.h"
int ft_is_sorted(int *in) int ft_is_sortee(int *in)
{ {
unsigned int *tab; unsigned int *tab;
unsigned int prev; unsigned int prev;
unsigned int i; unsigned int i;
int shift; 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; tab = (unsigned int *) in;
prev = tab[0]; prev = tab[0];
i = 1; i = 1;
@ -32,3 +32,8 @@ int ft_is_sorted(int *in)
} }
return (1); return (1);
} }
int ft_is_sorted(int *in)
{
return (ft_bit_finder_right(ft_get_bit_min(in), 1) == 31);
}

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/15 18:16:31 by cchauvet #+# #+# */ /* 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) 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)) while (!ft_is_sorted(tab_a))
{ {
i = ft_tablen(tab_a); tab_index = ft_tablen(tab_a) - 1;
while (--i >= 0 && !ft_is_sorted(tab_a)) 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); ft_pb(tab_a, tab_b);
tab_index--;
}
else else
ft_ra(tab_a); ft_ra(tab_a);
loop_index--;
} }
while (tab_b[0] != -1) while (tab_b[0] != -1)
ft_pa(tab_a, tab_b); ft_pa(tab_a, tab_b);
i = ft_tablen(tab_a); tab_index = ft_tablen(tab_a);
while (--i >= 0 && !ft_is_sorted(tab_a)) while (--tab_index >= 0 && !ft_is_sorted(tab_a))
tab_a[i] = tab_a[i] << 1; tab_a[tab_index] = tab_a[tab_index] << 1;
} }
free(tab_a);
free(tab_b);
} }

Binary file not shown.

92
ft_split.c Normal file
View 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
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 17:10:47 by cchauvet #+# #+# */ /* 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])) if (!ft_isnum(argv[i]))
{ {
ft_putstr("Erreur: args doesn't containe only numbers !"); write(2, "Error\n", 6);
return (1); return (1);
} }
tab_a[i - 1] = ft_atoi(argv[i]); tab_a[i - 1] = ft_atoi(argv[i]);

BIN
main.o

Binary file not shown.

BIN
push_swap

Binary file not shown.

1
push_swap_tester Submodule

@ -0,0 +1 @@
Subproject commit 59628457df966b6a6a12e63cecaa29456d2ed250

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:19:44 by cchauvet #+# #+# */ /* 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_isnum(char *str);
int ft_atoi(char *str); int ft_atoi(char *str);
void ft_putstr(char *str); void ft_putstr(char *str);
char **ft_split(const char *s, char c);
void ft_sort(int *tab, int size); void ft_sort(int *tab, int size);
int ft_get_max_index(int *tab, int len); int ft_get_max_index(int *tab, int len);