started redo error check parsing
This commit is contained in:
5
Makefile
5
Makefile
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
|
||||
# Updated: 2024/03/11 15:45:33 by adjoly ### ########.fr #
|
||||
# Updated: 2024/03/13 13:21:22 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,7 +19,6 @@ OBJSDIR = obj/
|
||||
SRCDIR = src/
|
||||
|
||||
SRCS = main.c \
|
||||
check_error.c \
|
||||
print_stack.c \
|
||||
parsing.c \
|
||||
stack/ft_stackadd_back.c \
|
||||
@ -37,7 +36,9 @@ SRCS = main.c \
|
||||
algo/algo.c \
|
||||
algo/insertion.c \
|
||||
algo/median.c \
|
||||
algo/small_mouv.c \
|
||||
utils/is_sorted.c \
|
||||
utils/print_error.c \
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o))
|
||||
|
||||
|
2
libft
2
libft
Submodule libft updated: 63a5504b82...4ce51959ed
8
mouv
Normal file
8
mouv
Normal file
@ -0,0 +1,8 @@
|
||||
1 2 3
|
||||
3 2 1 ra ra ok
|
||||
|
||||
1 3 2 rra sa ok
|
||||
2 3 1 rra ok
|
||||
|
||||
2 1 3 sa ok
|
||||
3 1 2 ra
|
BIN
obj/algo/algo.o
BIN
obj/algo/algo.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
obj/parsing.o
BIN
obj/parsing.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/21 17:29:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 16:06:26 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/03/12 15:37:38 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -49,9 +49,13 @@ void ft_algo(t_stack **stack_a, t_stack **stack_b)
|
||||
}
|
||||
if (ft_stacksize(*stack_a) == 3)
|
||||
{
|
||||
sort_three(stack_a);
|
||||
return ;
|
||||
}
|
||||
if (ft_stacksize(*stack_a) == 5)
|
||||
{
|
||||
sort_five(stack_a, stack_b);
|
||||
return ;
|
||||
}
|
||||
send_to_stack_b(stack_a, stack_b);
|
||||
while_insert(stack_a, stack_b);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/23 14:49:14 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 16:03:14 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/03/12 14:42:06 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,8 +14,6 @@
|
||||
|
||||
void prepare_to_send_a(t_stack **stack_b, size_t lowest_cost_b)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (lowest_cost_b < (ft_stacksize(*stack_b) / 2))
|
||||
{
|
||||
while (stack_b && *stack_b && lowest_cost_b > 0)
|
||||
@ -26,7 +24,6 @@ void prepare_to_send_a(t_stack **stack_b, size_t lowest_cost_b)
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
while (stack_b && *stack_b && lowest_cost_b < ft_stacksize(*stack_b))
|
||||
{
|
||||
ft_reverserotate_b(stack_b);
|
||||
|
@ -6,16 +6,58 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/11 16:12:47 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 16:24:11 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/03/12 17:20:50 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../push_swap.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
void sort_three(t_stack **stack_a)
|
||||
void sort_three(t_stack **stack_a)
|
||||
{
|
||||
if ((*stack_a)->nb > (*stack_a)->next->nb)
|
||||
ft_swap_a(*stack_a);
|
||||
if (get_stack_max(stack_a) == 2)
|
||||
ft_swap_a(*stack_a);
|
||||
else if (get_stack_max(stack_a) == 2 || get_stack_max(stack_a) == 0)
|
||||
ft_rotatestack_a(stack_a);
|
||||
else if (get_stack_max(stack_a) == 1)
|
||||
ft_reverserotate_a(stack_a);
|
||||
if (ft_is_sort(stack_a) == FALSE)
|
||||
sort_three(stack_a);
|
||||
}
|
||||
|
||||
void push_min_to_b(t_stack **stack_a, t_stack **stack_b)
|
||||
{
|
||||
size_t i_min;
|
||||
size_t i;
|
||||
|
||||
i_min = get_stack_min(stack_a);
|
||||
if (i_min < (ft_stacksize(*stack_a) / 2))
|
||||
{
|
||||
while (i_min > 0)
|
||||
{
|
||||
ft_rotatestack_a(stack_a);
|
||||
i_min--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = ft_stacksize(*stack_a);
|
||||
while (i_min < i)
|
||||
{
|
||||
ft_reverserotate_a(stack_a);
|
||||
i_min++;
|
||||
}
|
||||
}
|
||||
ft_push_b(stack_a, stack_b);
|
||||
}
|
||||
|
||||
void sort_five(t_stack **stack_a, t_stack **stack_b)
|
||||
{
|
||||
push_min_to_b(stack_a, stack_b);
|
||||
push_min_to_b(stack_a, stack_b);
|
||||
sort_three(stack_a);
|
||||
ft_push_a(stack_a, stack_b);
|
||||
ft_push_a(stack_a, stack_b);
|
||||
if (ft_is_sort(stack_a) == FALSE)
|
||||
ft_swap_a(*stack_a);
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_error.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/15 13:45:25 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 15:56:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ft_check_args_format(char **av)
|
||||
{
|
||||
char **tmp;
|
||||
char *tmp_av;
|
||||
|
||||
tmp = av;
|
||||
tmp++;
|
||||
while (*tmp)
|
||||
{
|
||||
tmp_av = *tmp;
|
||||
while (*tmp_av)
|
||||
{
|
||||
if (!ft_isdigit(*tmp_av) && *tmp_av != 32 \
|
||||
&& *tmp_av != '-' && *tmp_av != '+')
|
||||
{
|
||||
ft_putendl_fd("Error", STDERR_FILENO);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
tmp_av++;
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_check_double(t_stack **stack)
|
||||
{
|
||||
t_stack *index;
|
||||
t_stack *tmp;
|
||||
|
||||
index = *stack;
|
||||
while (index)
|
||||
{
|
||||
tmp = index->next;
|
||||
while (tmp)
|
||||
{
|
||||
if (index->nb == tmp->nb)
|
||||
{
|
||||
ft_stackclear(stack);
|
||||
ft_putendl_fd("Error", STDERR_FILENO);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
index = index->next;
|
||||
}
|
||||
}
|
66
src/main.c
66
src/main.c
@ -6,70 +6,78 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 12:14:22 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/08 14:17:09 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/03/13 14:44:42 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ft_check_args(char **av)
|
||||
void check_invalid_char(char **av)
|
||||
{
|
||||
char **tmp;
|
||||
char *tmp_av;
|
||||
char *tmp_args;
|
||||
|
||||
tmp = av;
|
||||
tmp++;
|
||||
while (*tmp)
|
||||
{
|
||||
tmp_av = *tmp;
|
||||
while (*tmp_av)
|
||||
tmp_args = *tmp;
|
||||
while (*tmp_args)
|
||||
{
|
||||
if ((*tmp_av == '+' || *tmp_av == '-'))
|
||||
{
|
||||
if (!ft_isdigit(*tmp_av + 1))
|
||||
{
|
||||
ft_putendl_fd("Error", STDERR_FILENO);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!*tmp_av && ft_isdigit(*tmp_av))
|
||||
tmp_av++;
|
||||
}
|
||||
}
|
||||
tmp_av++;
|
||||
if (!ft_isdigit(*tmp_args) && *tmp_args != '-' && *tmp_args != '+' && *tmp_args != 32)
|
||||
ft_senderror();
|
||||
tmp_args++;
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void check_double(t_stack **stack)
|
||||
{
|
||||
t_stack *tmp;
|
||||
t_stack *check_dup;
|
||||
|
||||
tmp = *stack;
|
||||
while (tmp)
|
||||
{
|
||||
check_dup = tmp->next;
|
||||
while (check_dup)
|
||||
{
|
||||
if (check_dup->nb == tmp->nb)
|
||||
{
|
||||
ft_stackclear(stack);
|
||||
ft_senderror();
|
||||
}
|
||||
check_dup = check_dup->next;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_stack *stack_a;
|
||||
t_stack *stack_b;
|
||||
|
||||
if (ac < 2)
|
||||
{
|
||||
ft_putendl_fd("Error", STDERR_FILENO);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
ft_check_args_format(av);
|
||||
ft_check_args(av);
|
||||
return (EXIT_SUCCESS);
|
||||
check_invalid_char(av);
|
||||
stack_b = NULL;
|
||||
stack_a = ft_parsing(av);
|
||||
if (ft_stacksize(stack_a) <= 1)
|
||||
{
|
||||
ft_stackclear(&stack_a);
|
||||
exit(EXIT_SUCCESS);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
if (ft_is_sort(&stack_a) == TRUE)
|
||||
{
|
||||
ft_stackclear(&stack_a);
|
||||
exit(EXIT_SUCCESS);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
ft_check_double(&stack_a);
|
||||
check_double(&stack_a);
|
||||
ft_algo(&stack_a, &stack_b);
|
||||
ft_stackclear(&stack_a);
|
||||
ft_stackclear(&stack_b);
|
||||
return (0);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
12
src/mouv
12
src/mouv
@ -1,8 +1,8 @@
|
||||
1 2 3 nope
|
||||
1 3 2 sa ra
|
||||
1 2 3
|
||||
3 2 1 ra ra
|
||||
|
||||
3 2 1 sa rra
|
||||
3 1 2 ra
|
||||
|
||||
2 1 3 sa
|
||||
2 3 1 rra
|
||||
1 3 2 rra sa
|
||||
|
||||
3 1 2 ra
|
||||
2 1 3 sa
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 12:05:43 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 15:58:28 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/03/13 13:05:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 12:18:29 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 16:07:50 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/03/13 14:35:19 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -55,15 +55,15 @@ void while_insert(t_stack **stack_a, t_stack **stack_b);
|
||||
size_t get_lowest_cost(t_stack **stack_a, t_stack **stack_b);
|
||||
t_boolean ft_is_sort(t_stack **stack);
|
||||
int find_q_one(t_stack **stack);
|
||||
void sort_three(t_stack **stack_a);
|
||||
void sort_five(t_stack **stack_a, t_stack **stack_b);
|
||||
|
||||
// get_min_max
|
||||
size_t get_stack_max(t_stack **stack);
|
||||
size_t get_stack_min(t_stack **stack);
|
||||
|
||||
// error checkin
|
||||
void ft_check_args_format(char **av);
|
||||
t_stack *ft_parsing(char **av);
|
||||
void ft_check_double(t_stack **stack);
|
||||
void ft_print_stack(t_stack *stack);
|
||||
|
||||
// utils
|
||||
|
Reference in New Issue
Block a user