#include "pushswap.h" /* ** this function is only used to print the stack and the action ** then it launch the action (swap, push, rotate) */ void action(t_stack *stack_a, t_stack *stack_b, t_list *solution, int flag, void (*sp)(t_list *pack)) { if (!flag) // if flag == 0, don't print anything return ; if (!(*solution)) // to print only at first call { print_stack(stack_a, 'a'); print_stack(stack_b, 'b'); } sp(pack); // the action to execute ft_putchar('t'); ft_printf("%s\n", (*solution)->content); ft_putchar('u'); print_stack(stack_a, 'a'); print_stack(stack_b, 'b'); } /* ** */ t_list *sort_algo(t_stack *a, int f) { t_stack *b; t_list *solution; solution = NULL; if(!(b = ft_calloc(1, sizeof(t_stack)))) ps_stop(a, b, NULL, 2); action(a, b, solution, f, sa); action(a, b, solution, f, sa); // sa(stack_a, stack_b, &solution); // sb(stack_a, stack_b, &solution); // ss(stack_a, stack_b, &solution); // pa(stack_a, stack_b, &solution); // pb(stack_a, stack_b, &solution); // ra(stack_a, stack_b, &solution); // rb(stack_a, stack_b, &solution); // rr(stack_a, stack_b, &solution); // rra(stack_a, stack_b, &solution); // rrb(stack_a, stack_b, &solution); // rrr(stack_a, stack_b, &solution); if (flag) ft_putchar('\n'); ps_stop(NULL, pack->next->content, NULL, -1); // pack->next->content is stack_b return (pack->next->next->content); // pack->next->next->content is t_list *solution }