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

View File

@@ -55,6 +55,10 @@ $(ODIR):
$(ODIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
libft:
make re -C $(LDIR)
make $(NAME)
clean:
/bin/rm -f $(OBJS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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

BIN
push_swap

Binary file not shown.

View File

@@ -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);
}

View File

@@ -62,5 +62,6 @@ void print_result(t_list *result, int flag)
ft_printf(" %s\n", part[2]);
}
result = result->next;
free(part);
}
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}