ca marche

This commit is contained in:
Camille Chauvet 2022-12-09 19:13:15 +01:00
parent afc4f2d0b3
commit 55119130da
14 changed files with 90 additions and 16 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/09 14:37:12 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_bozo_sort.c ft_get_max.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
a.out

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 14:24:03 by cchauvet #+# #+# */
/* Updated: 2022/12/09 15:21:17 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 19:11:58 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,19 +16,31 @@ void ft_bozo_sort(t_tab tab_a, t_tab tab_b)
{
if (ft_is_sorted(tab_a))
return ;
while (ft_tablen(tab_a) > 2)
while (ft_tablen(tab_a) > 3)
{
while (tab_a[0] > 1 && 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 (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);
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_rra(tab_a);
if (ft_tablen(tab_b) > 1)
if (ft_is_sorted(tab_b))
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);

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)
{

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 */
/* */
/* ************************************************************************** */

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 18:05:06 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.

BIN
ft_sort.o

Binary file not shown.

BIN
push_swap

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/09 14:34:39 by cchauvet ### ########.fr */
/* Updated: 2022/12/09 18:51:58 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,7 @@
# include <unistd.h>
# include <stdlib.h>
# include <limits.h>
# include <stdio.h>
//# include <stdio.h>
# define STOP_VALUE 4294967295
int ft_isnum(char *str);
@ -40,6 +40,9 @@ 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