diff --git a/Makefile b/Makefile index 589f09f..bf9c1f2 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,10 @@ $(ODIR): $(ODIR)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< +libft: + make re -C $(LDIR) + make $(NAME) + clean: /bin/rm -f $(OBJS) diff --git a/builds/algo.o b/builds/algo.o index 80a5d0c..7fdc3e4 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/print.o b/builds/print.o index 08ed267..f674759 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/builds/push_swap.o b/builds/push_swap.o index c1666a5..b3e78bc 100644 Binary files a/builds/push_swap.o and b/builds/push_swap.o differ diff --git a/builds/reverse_rotate.o b/builds/reverse_rotate.o index 5cb39d0..98ca444 100644 Binary files a/builds/reverse_rotate.o and b/builds/reverse_rotate.o differ diff --git a/builds/rotate.o b/builds/rotate.o index d05d39a..099a619 100644 Binary files a/builds/rotate.o and b/builds/rotate.o differ diff --git a/builds/stop.o b/builds/stop.o index 145d304..53d51e1 100644 Binary files a/builds/stop.o and b/builds/stop.o differ diff --git a/includes/push_swap.h b/includes/push_swap.h index ba6547f..edadc27 100644 --- a/includes/push_swap.h +++ b/includes/push_swap.h @@ -30,7 +30,7 @@ t_list *launch_algo(t_stack *stack); */ void ps_usage(void); void ps_error(int i); -void ps_stop(t_stack *a, t_stack *b, t_list *lst, int i); +void ps_stop(t_stack *stack, t_list *lst, int i); /* ** algo.c diff --git a/push_swap b/push_swap index 400f861..acb6c8d 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index 255783c..0c25839 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -13,5 +13,6 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *solution) sa(a, &solution); sb(b, &solution); sa(a, &solution); + rra(a, &solution); } diff --git a/srcs/print.c b/srcs/print.c index 18f2721..a8df9ab 100644 --- a/srcs/print.c +++ b/srcs/print.c @@ -62,5 +62,6 @@ void print_result(t_list *result, int flag) ft_printf(" %s\n", part[2]); } result = result->next; + free(part); } } diff --git a/srcs/push_swap.c b/srcs/push_swap.c index 73f06dd..da46b2f 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -9,7 +9,7 @@ void is_valid(int ac, char **av) { if (ac < 2) - ps_stop(NULL, NULL, NULL, 1); + ps_stop(NULL, NULL, 1); (void)av; // check more error } @@ -39,7 +39,7 @@ t_stack *init_stack(int ac, char **av) while (--ac) { if (!(start = ft_calloc(1, sizeof(t_stack)))) - ps_stop(start, NULL, NULL, 2); + ps_stop(NULL, NULL, 2); start->n = ft_atoi(av[ac]); start->next = tmp; tmp = start; @@ -90,5 +90,6 @@ int main(int ac, char **av) stack = init_stack(ac, av); result = launch_algo(stack); print_result(result, flag); + ps_stop(NULL, result, 0); return(0); } diff --git a/srcs/reverse_rotate.c b/srcs/reverse_rotate.c index d8ff985..bfe8b7c 100644 --- a/srcs/reverse_rotate.c +++ b/srcs/reverse_rotate.c @@ -1,6 +1,31 @@ #include "push_swap.h" -t_list *rra(t_stack **stack, t_list **lst); -t_list *rrb(t_stack **stack, t_list **lst); +t_list *rra(t_stack **stack, t_list **lst) +{ + t_stack *tmp; + t_stack *before; + + tmp = *stack; + if (!tmp || !(tmp->next)) + return (NULL); + while (tmp->next) + { + before = tmp; + tmp = tmp->next; + } + tmp->next = *stack; + *stack = tmp; + before->next = NULL; + fill_solution(*lst, ft_strdup("rra")); + return (NULL); +} + +t_list *rrb(t_stack **stack, t_list **lst) +{ + t_stack *tmp; + + tmp = *stack; + return (NULL); +} t_list *rrr(t_stack **a, t_stack **b, t_list **lst); diff --git a/srcs/stop.c b/srcs/stop.c index eb81e4a..b94a4f4 100644 --- a/srcs/stop.c +++ b/srcs/stop.c @@ -13,19 +13,33 @@ void ps_error(int err) ps_usage(); if (err == 2) ft_printf("error\n"); + exit(0); } -void ps_stop(t_stack *stack_a, t_stack *stack_b, t_list *solution, int err) +void ps_stop(t_stack *stack, t_list *lst, int err) { - if (stack_a) - ft_lstclear((t_list **)&stack_a, NULL); - if (stack_b) - ft_lstclear((t_list **)&stack_b, NULL); - if (solution) + t_stack **a; + t_stack **b; + t_list *solution; + + (void)stack; + (void)a; + (void)b; + (void)solution; + (void)lst; + if (stack) + ft_lstclear((t_list **)&stack, NULL); + if (lst) + { + a = lst->content; + b = lst->next->content; + solution = lst->next->next; + ft_lstclear((t_list **)a, NULL); + ft_lstclear((t_list **)b, NULL); ft_lstclear(&solution, free); + } if (err < 0) return ; else if (err > 0) ps_error(err); - exit(0); }