Compare commits

...

4 Commits

Author SHA1 Message Date
Camille Chauvet
224d9bb1a4 normed 2022-12-09 19:17:57 +01:00
Camille Chauvet
55119130da ca marche 2022-12-09 19:13:15 +01:00
Camille Chauvet
afc4f2d0b3 work but bozo sort not work 2022-12-09 15:22:02 +01:00
Camille Chauvet
1d81c47cfd ca marche avec print 2022-12-07 14:19:16 +01:00
28 changed files with 154 additions and 25 deletions

View File

@ -6,11 +6,11 @@
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/11/28 16:34:37 by cchauvet #+# #+# #
# Updated: 2022/12/06 13:32:50 by cchauvet ### ########.fr #
# Updated: 2022/12/09 18:03:57 by cchauvet ### ########.fr #
# #
# **************************************************************************** #
SRCS = ft_swap.c ft_putstr.c ft_p.c ft_sort.c ft_tablen.c main.c ft_atoi.c ft_radix.c ft_isnum.c ft_r.c ft_is_sorted.c ft_get_max.c ft_bitlen.c
SRCS = ft_swap.c ft_putstr.c ft_p.c ft_sort.c ft_tablen.c main.c ft_atoi.c ft_radix.c ft_isnum.c ft_r.c ft_is_sorted.c ft_bozo_sort.c ft_get_max.c ft_rr.c ft_s.c
OBJS = ${SRCS:.c=.o}

BIN
ft_atoi.o Normal file

Binary file not shown.

51
ft_bozo_sort.c Normal file
View File

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bozo_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 14:24:03 by cchauvet #+# #+# */
/* Updated: 2022/12/09 19:14:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
static void ft_specific_bozo_sort(t_tab tab_a, t_tab tab_b)
{
if (tab_a[0] == tab_a[1] - 1)
ft_rra(tab_a);
if (tab_a[0] == tab_a[1] + 1 && tab_a[1] == tab_a[2] + 1)
{
ft_ra(tab_a);
ft_sa(tab_a);
}
if (tab_a[0] == tab_a[1] + 1)
ft_sa(tab_a);
}
void ft_bozo_sort(t_tab tab_a, t_tab tab_b)
{
if (ft_is_sorted(tab_a))
return ;
while (ft_tablen(tab_a) > 3)
{
while ((long) tab_a[0] >= ft_tablen(tab_a) + ft_tablen(tab_b) - 3)
ft_ra(tab_a);
ft_pb(tab_a, tab_b);
}
if (!ft_is_sorted(tab_a))
{
ft_pb(tab_a, tab_b);
if (!ft_is_sorted(tab_a))
ft_ra(tab_a);
ft_pa(tab_a, tab_b);
if (!ft_is_sorted(tab_a))
ft_ra(tab_a);
}
if (ft_is_sorted(tab_b) && ft_tablen(tab_b) > 1)
ft_rb(tab_b);
while (ft_tablen(tab_b) != 0)
ft_pa(tab_a, tab_b);
}

BIN
ft_bozo_sort.o Normal file

Binary file not shown.

BIN
ft_get_max.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 14:41:08 by cchauvet #+# #+# */
/* Updated: 2022/12/06 13:30:52 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 18:06:59 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,10 @@ int ft_is_sorted(unsigned int *tab)
{
int i;
if (ft_tablen(tab) == 0)
return (0);
if (ft_tablen(tab) == 1)
return (1);
i = 1;
while (tab[i] != STOP_VALUE)
{

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 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{
int size_src;
int size_dst;
unsigned int i;
size_src = ft_tablen(tab_src);
size_dst = ft_tablen(tab_dst);
if (size_src == 0)
return ;
tab_dst[size_dst] = tab_src[size_src - 1];
tab_dst[size_dst + 1] = -1;
tab_src[size_src - 1] = -1;
i = ft_tablen(tab_dst) + 1;
while (i > 0)
{
tab_dst[i] = tab_dst[i - 1];
i--;
}
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)

BIN
ft_p.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:24:45 by cchauvet #+# #+# */
/* Updated: 2022/11/29 14:38:32 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 18:53:38 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */

BIN
ft_putstr.o Normal file

Binary file not shown.

10
ft_r.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/28 16:50:03 by cchauvet #+# #+# */
/* Updated: 2022/12/01 17:42:30 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 14:36:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@ static void ft_r(unsigned int *tab)
i = 0;
while (tab[i + 1] != STOP_VALUE)
{
ft_swap(tab + i, tab + i + 1);
ft_swap(tab + i + 1, tab + i);
i++;
}
}
@ -29,3 +29,9 @@ void ft_ra(unsigned int *tab)
ft_r(tab);
ft_putstr("ra\n");
}
void ft_rb(unsigned int *tab)
{
ft_r(tab);
ft_putstr("rb\n");
}

BIN
ft_r.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/15 18:16:31 by cchauvet #+# #+# */
/* Updated: 2022/12/06 17:22:52 by cchauvet ### ########.fr */
/* Updated: 2022/12/07 14:33:00 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,12 +18,12 @@ void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b)
unsigned int y;
i = 0;
while (!ft_is_sorted(tab_a) && i < sizeof(unsigned int) * 8)
while (!ft_is_sorted(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);
else
ft_ra(tab_a);

BIN
ft_radix.o Normal file

Binary file not shown.

31
ft_rr.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/28 16:50:03 by cchauvet #+# #+# */
/* Updated: 2022/12/09 18:38:14 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
static void ft_rr(unsigned int *tab)
{
int i;
i = ft_tablen(tab) - 1;
while (i > 0)
{
ft_swap(tab + i - 1, tab + i);
i--;
}
}
void ft_rra(unsigned int *tab)
{
ft_rr(tab);
ft_putstr("rra\n");
}

BIN
ft_rr.o Normal file

Binary file not shown.

24
ft_s.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_s.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 18:00:12 by cchauvet #+# #+# */
/* Updated: 2022/12/09 19:15:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
static void ft_s(t_tab tab)
{
ft_swap(tab + 0, tab + 1);
}
void ft_sa(t_tab tab)
{
ft_s(tab);
ft_putstr("sa\n");
}

BIN
ft_s.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 19:47:56 by cchauvet #+# #+# */
/* Updated: 2022/12/06 17:27:05 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 14:40:33 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -61,7 +61,10 @@ void ft_sort(long int *tab_in, int size_a)
tab_a = NULL;
if (ft_tab_init(tab_in, size_a, &tab_a, &tab_b) == NULL)
return ;
if (ft_tablen(tab_a) > 5)
ft_radix_sort(tab_a, tab_b);
else
ft_bozo_sort(tab_a, tab_b);
free(tab_a);
free(tab_b);
}

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.

3
main.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 17:10:47 by cchauvet #+# #+# */
/* Updated: 2022/12/04 19:44:25 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 15:00:05 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,6 +26,7 @@ int main(int argc, char *argv[])
if (!ft_isnum(argv[i]))
{
write(2, "Error\n", 6);
free(tab_a);
return (1);
}
tab_a[i - 1] = ft_atoi(argv[i]);

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 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:19:44 by cchauvet #+# #+# */
/* Updated: 2022/12/06 17:30:20 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 18:51:58 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
# include <unistd.h>
# include <stdlib.h>
# include <limits.h>
//# include <stdio.h>
# define STOP_VALUE 4294967295
int ft_isnum(char *str);
@ -33,12 +34,15 @@ int ft_is_sorted(unsigned int *in);
unsigned int ft_bitlen(unsigned int nb);
void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b);
void ft_bozo_sort(unsigned int *tab_a, unsigned 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);
void ft_rra(unsigned int *tab_a);
void ft_rrb(unsigned int *tab_b);
void ft_sa(unsigned int *tab_a);
typedef unsigned int * t_tab;
#endif