work but bozo sort not work
This commit is contained in:
parent
1d81c47cfd
commit
afc4f2d0b3
4
Makefile
4
Makefile
@ -6,11 +6,11 @@
|
|||||||
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
|
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/11/28 16:34:37 by cchauvet #+# #+# #
|
# Created: 2022/11/28 16:34:37 by cchauvet #+# #+# #
|
||||||
# Updated: 2022/12/06 13:32:50 by cchauvet ### ########.fr #
|
# Updated: 2022/12/09 14:37:12 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
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
BIN
ft_bitlen.o
BIN
ft_bitlen.o
Binary file not shown.
35
ft_bozo_sort.c
Normal file
35
ft_bozo_sort.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_bozo_sort.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "pushswap.h"
|
||||||
|
|
||||||
|
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 (tab_a[0] > 1 && ft_tablen(tab_a) != 3)
|
||||||
|
ft_ra(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_rb(tab_b);
|
||||||
|
while (ft_tablen(tab_b) != 0)
|
||||||
|
ft_pa(tab_a, tab_b);
|
||||||
|
}
|
BIN
ft_bozo_sort.o
Normal file
BIN
ft_bozo_sort.o
Normal file
Binary file not shown.
8
ft_r.c
8
ft_r.c
@ -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/07 13:29:57 by cchauvet ### ########.fr */
|
/* Updated: 2022/12/09 14:36:50 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -29,3 +29,9 @@ void ft_ra(unsigned int *tab)
|
|||||||
ft_r(tab);
|
ft_r(tab);
|
||||||
ft_putstr("ra\n");
|
ft_putstr("ra\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_rb(unsigned int *tab)
|
||||||
|
{
|
||||||
|
ft_r(tab);
|
||||||
|
ft_putstr("rb\n");
|
||||||
|
}
|
||||||
|
19
ft_radix.c
19
ft_radix.c
@ -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/07 14:18:44 by cchauvet ### ########.fr */
|
/* Updated: 2022/12/07 14:33:00 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,12 +16,9 @@ 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 < bit_shift)
|
while (!ft_is_sorted(tab_a))
|
||||||
{
|
{
|
||||||
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)))
|
||||||
@ -31,21 +28,9 @@ void ft_radix_sort(unsigned int *tab_a, unsigned int *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
BIN
ft_radix.o
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/11/08 19:47:56 by cchauvet #+# #+# */
|
/* 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;
|
tab_a = NULL;
|
||||||
if (ft_tab_init(tab_in, size_a, &tab_a, &tab_b) == NULL)
|
if (ft_tab_init(tab_in, size_a, &tab_a, &tab_b) == NULL)
|
||||||
return ;
|
return ;
|
||||||
|
if (ft_tablen(tab_a) > 5)
|
||||||
ft_radix_sort(tab_a, tab_b);
|
ft_radix_sort(tab_a, tab_b);
|
||||||
|
else
|
||||||
|
ft_bozo_sort(tab_a, tab_b);
|
||||||
free(tab_a);
|
free(tab_a);
|
||||||
free(tab_b);
|
free(tab_b);
|
||||||
}
|
}
|
||||||
|
3
main.c
3
main.c
@ -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/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]))
|
if (!ft_isnum(argv[i]))
|
||||||
{
|
{
|
||||||
write(2, "Error\n", 6);
|
write(2, "Error\n", 6);
|
||||||
|
free(tab_a);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
tab_a[i - 1] = ft_atoi(argv[i]);
|
tab_a[i - 1] = ft_atoi(argv[i]);
|
||||||
|
@ -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/07 12:52:56 by cchauvet ### ########.fr */
|
/* Updated: 2022/12/09 14:34:39 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ int ft_is_sorted(unsigned int *in);
|
|||||||
unsigned int ft_bitlen(unsigned int nb);
|
unsigned int ft_bitlen(unsigned int nb);
|
||||||
|
|
||||||
void ft_radix_sort(unsigned int *tab_a, unsigned int *tab_b);
|
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_swap(unsigned int *a, unsigned int *b);
|
||||||
void ft_pa(unsigned int *tab_a, unsigned int *tab_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_pb(unsigned int *tab_a, unsigned int *tab_b);
|
||||||
|
Loading…
Reference in New Issue
Block a user