Compare commits

..

No commits in common. "224d9bb1a40a4df533e055d697cf58f2505258c4" and "3fc423de4ad5b9a62ec2799427c5b1ec69c7d42a" have entirely different histories.

28 changed files with 25 additions and 154 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 18:03:57 by cchauvet ### ########.fr #
# Updated: 2022/12/06 13:32:50 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 ft_rr.c ft_s.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_get_max.c ft_bitlen.c
OBJS = ${SRCS:.c=.o}

BIN
ft_atoi.o

Binary file not shown.

View File

@ -1,51 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

Binary file not shown.

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/09 18:06:59 by cchauvet ### ########.fr */
/* Updated: 2022/12/06 13:30:52 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,10 +16,6 @@ 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.

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/07 14:15:24 by cchauvet ### ########.fr */
/* Updated: 2022/12/06 17:22:35 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,21 +14,16 @@
void ft_p(unsigned int *tab_src, unsigned int *tab_dst)
{
unsigned int i;
int size_src;
int size_dst;
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++;
}
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;
}
void ft_pb(unsigned int *tab_a, unsigned int *tab_b)

BIN
ft_p.o

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/12/09 18:53:38 by cchauvet ### ########.fr */
/* Updated: 2022/11/29 14:38:32 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */

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/09 14:36:50 by cchauvet ### ########.fr */
/* Updated: 2022/12/01 17:42:30 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 + 1, tab + i);
ft_swap(tab + i, tab + i + 1);
i++;
}
}
@ -29,9 +29,3 @@ 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

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/07 14:33:00 by cchauvet ### ########.fr */
/* Updated: 2022/12/06 17:22:52 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))
while (!ft_is_sorted(tab_a) && i < sizeof(unsigned int) * 8)
{
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[0] >> i) & 1) == 0)
if (((tab_a[ft_tablen(tab_a) - 1] >> i) & 1) == 1)
ft_pb(tab_a, tab_b);
else
ft_ra(tab_a);

Binary file not shown.

31
ft_rr.c
View File

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

Binary file not shown.

24
ft_s.c
View File

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

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/09 14:40:33 by cchauvet ### ########.fr */
/* Updated: 2022/12/06 17:27:05 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -61,10 +61,7 @@ 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

Binary file not shown.

BIN
ft_swap.o

Binary file not shown.

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/09 15:00:05 by cchauvet ### ########.fr */
/* Updated: 2022/12/04 19:44:25 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,6 @@ 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

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