ca marche avec print

This commit is contained in:
Camille Chauvet 2022-12-07 14:19:16 +01:00
parent 3fc423de4a
commit 1d81c47cfd
20 changed files with 67 additions and 17 deletions

BIN
a.out Executable file

Binary file not shown.

BIN
ft_atoi.o Normal file

Binary file not shown.

BIN
ft_bitlen.o Normal file

Binary file not shown.

BIN
ft_get_max.o Normal file

Binary file not shown.

BIN
ft_is_sorted.o Normal file

Binary file not shown.

BIN
ft_isnum.o Normal file

Binary file not shown.

25
ft_p.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 16:38:34 by cchauvet #+# #+# */ /* Created: 2022/11/09 16:38:34 by cchauvet #+# #+# */
/* Updated: 2022/12/06 17:22:35 by cchauvet ### ########.fr */ /* Updated: 2022/12/07 14:15:24 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,16 +14,21 @@
void ft_p(unsigned int *tab_src, unsigned int *tab_dst) void ft_p(unsigned int *tab_src, unsigned int *tab_dst)
{ {
int size_src; unsigned int i;
int size_dst;
size_src = ft_tablen(tab_src); i = ft_tablen(tab_dst) + 1;
size_dst = ft_tablen(tab_dst); while (i > 0)
if (size_src == 0) {
return ; tab_dst[i] = tab_dst[i - 1];
tab_dst[size_dst] = tab_src[size_src - 1]; i--;
tab_dst[size_dst + 1] = -1; }
tab_src[size_src - 1] = -1; tab_dst[0] = tab_src[0];
i = 0;
while (tab_src[i] != STOP_VALUE)
{
tab_src[i] = tab_src[i + 1];
i++;
}
} }
void ft_pb(unsigned int *tab_a, unsigned int *tab_b) void ft_pb(unsigned int *tab_a, unsigned int *tab_b)

BIN
ft_p.o Normal file

Binary file not shown.

BIN
ft_putstr.o Normal file

Binary file not shown.

4
ft_r.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/28 16:50:03 by cchauvet #+# #+# */ /* Created: 2022/11/28 16:50:03 by cchauvet #+# #+# */
/* Updated: 2022/12/01 17:42:30 by cchauvet ### ########.fr */ /* Updated: 2022/12/07 13:29:57 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,7 @@ static void ft_r(unsigned int *tab)
i = 0; i = 0;
while (tab[i + 1] != STOP_VALUE) while (tab[i + 1] != STOP_VALUE)
{ {
ft_swap(tab + i, tab + i + 1); ft_swap(tab + i + 1, tab + i);
i++; i++;
} }
} }

BIN
ft_r.o Normal 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/15 18:16:31 by cchauvet #+# #+# */ /* Created: 2022/11/15 18:16:31 by cchauvet #+# #+# */
/* Updated: 2022/12/06 17:22:52 by cchauvet ### ########.fr */ /* Updated: 2022/12/07 14:18:44 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,21 +16,36 @@ void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b)
{ {
unsigned int i; unsigned int i;
unsigned int y; unsigned int y;
unsigned int bit_shift;
int j;
bit_shift = ft_bitlen(ft_get_max(tab_a)) + 1;
i = 0; i = 0;
while (!ft_is_sorted(tab_a) && i < sizeof(unsigned int) * 8) while (!ft_is_sorted(tab_a) && i < bit_shift)
{ {
y = ft_tablen(tab_a); y = ft_tablen(tab_a);
while (0 < y && (!ft_is_sorted(tab_a) && !ft_tablen(tab_b))) while (0 < y && !(ft_is_sorted(tab_a) && !ft_tablen(tab_b)))
{ {
if (((tab_a[ft_tablen(tab_a) - 1] >> i) & 1) == 1) if (((tab_a[0] >> i) & 1) == 0)
ft_pb(tab_a, tab_b); ft_pb(tab_a, tab_b);
else else
ft_ra(tab_a); ft_ra(tab_a);
y--; y--;
j = 0;
printf("tab_a:\n");
while (tab_a[j] != STOP_VALUE)
printf("%d\n", tab_a[j++]);
j = 0;
printf("tab_b:\n");
while (tab_b[j] != STOP_VALUE)
printf("%d\n", tab_b[j++]);
} }
while (tab_b[0] != STOP_VALUE) while (tab_b[0] != STOP_VALUE)
ft_pa(tab_a, tab_b); ft_pa(tab_a, tab_b);
i++; i++;
j = 0;
printf("\n\nROUND[%d]\ntab_a:\n", i);
while (tab_a[j] != STOP_VALUE)
printf("%d\n", tab_a[j++]);
} }
} }

BIN
ft_radix.o Normal file

Binary file not shown.

BIN
ft_sort.o Normal file

Binary file not shown.

BIN
ft_swap.o Normal file

Binary file not shown.

BIN
ft_tablen.o Normal file

Binary file not shown.

BIN
main.o Normal file

Binary file not shown.

BIN
push_swap 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/08 18:19:44 by cchauvet #+# #+# */ /* Created: 2022/11/08 18:19:44 by cchauvet #+# #+# */
/* Updated: 2022/12/06 17:30:20 by cchauvet ### ########.fr */ /* Updated: 2022/12/07 12:52:56 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,7 @@
# include <unistd.h> # include <unistd.h>
# include <stdlib.h> # include <stdlib.h>
# include <limits.h> # include <limits.h>
# include <stdio.h>
# define STOP_VALUE 4294967295 # define STOP_VALUE 4294967295
int ft_isnum(char *str); int ft_isnum(char *str);

29
test.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 13:38:08 by cchauvet #+# #+# */
/* Updated: 2022/12/07 14:14:21 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
int main()
{
unsigned int tab_a[10] = {0, 1, 2, 3, 4, STOP_VALUE};
unsigned int tab_b[10] = {5, STOP_VALUE};
int i;
printf("tab_a\n");
i = 0;
while (tab_a[i] != STOP_VALUE)
printf("%d\n", tab_a[i++]);
ft_pa(tab_a, tab_b);
i = 0;
while (tab_a[i] != STOP_VALUE)
printf("%d\n", tab_a[i++]);
}