rra fonctionne

This commit is contained in:
hugogogo
2021-06-15 17:02:15 +02:00
parent dc99227f94
commit 9842a20f6e
14 changed files with 58 additions and 12 deletions
+4
View File
@@ -55,6 +55,10 @@ $(ODIR):
$(ODIR)/%.o: %.c $(ODIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
libft:
make re -C $(LDIR)
make $(NAME)
clean: clean:
/bin/rm -f $(OBJS) /bin/rm -f $(OBJS)
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -30,7 +30,7 @@ t_list *launch_algo(t_stack *stack);
*/ */
void ps_usage(void); void ps_usage(void);
void ps_error(int i); 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 ** algo.c
BIN
View File
Binary file not shown.
+1
View File
@@ -13,5 +13,6 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
sa(a, &solution); sa(a, &solution);
sb(b, &solution); sb(b, &solution);
sa(a, &solution); sa(a, &solution);
rra(a, &solution);
} }
+1
View File
@@ -62,5 +62,6 @@ void print_result(t_list *result, int flag)
ft_printf(" %s\n", part[2]); ft_printf(" %s\n", part[2]);
} }
result = result->next; result = result->next;
free(part);
} }
} }
+3 -2
View File
@@ -9,7 +9,7 @@
void is_valid(int ac, char **av) void is_valid(int ac, char **av)
{ {
if (ac < 2) if (ac < 2)
ps_stop(NULL, NULL, NULL, 1); ps_stop(NULL, NULL, 1);
(void)av; (void)av;
// check more error // check more error
} }
@@ -39,7 +39,7 @@ t_stack *init_stack(int ac, char **av)
while (--ac) while (--ac)
{ {
if (!(start = ft_calloc(1, sizeof(t_stack)))) 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->n = ft_atoi(av[ac]);
start->next = tmp; start->next = tmp;
tmp = start; tmp = start;
@@ -90,5 +90,6 @@ int main(int ac, char **av)
stack = init_stack(ac, av); stack = init_stack(ac, av);
result = launch_algo(stack); result = launch_algo(stack);
print_result(result, flag); print_result(result, flag);
ps_stop(NULL, result, 0);
return(0); return(0);
} }
+27 -2
View File
@@ -1,6 +1,31 @@
#include "push_swap.h" #include "push_swap.h"
t_list *rra(t_stack **stack, t_list **lst); t_list *rra(t_stack **stack, t_list **lst)
t_list *rrb(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); t_list *rrr(t_stack **a, t_stack **b, t_list **lst);
+21 -7
View File
@@ -13,19 +13,33 @@ void ps_error(int err)
ps_usage(); ps_usage();
if (err == 2) if (err == 2)
ft_printf("error\n"); 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) t_stack **a;
ft_lstclear((t_list **)&stack_a, NULL); t_stack **b;
if (stack_b) t_list *solution;
ft_lstclear((t_list **)&stack_b, NULL);
if (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); ft_lstclear(&solution, free);
}
if (err < 0) if (err < 0)
return ; return ;
else if (err > 0) else if (err > 0)
ps_error(err); ps_error(err);
exit(0);
} }