#include "pushswap.h" void sa(t_list *pack) { t_stack *stack_a; t_list **solution; int tmp; stack_a = pack->content; solution = pack->next->next->content; if (!stack_a->next) return ; tmp = stack_a->n; stack_a->n = stack_a->next->n; stack_a->next->n = tmp; (*solution)->content = ft_strdup("sa"); ft_lstadd_back(solution, ft_lstnew(NULL)); } /* ** this function */ void action(t_list *pack, void (*sp)(t_list *pack)) { t_stack *stack_a; t_stack *stack_b; t_list **solution; stack_a = pack->content; stack_b = pack->next->content; solution = pack->next->next->content; print_stack(stack_a); print_stack(stack_b); ft_printf("%s\n", (*solution)->content); sp(pack); } /* ** this function create the structures "solution" and "stack_b" ** and put their together with "stack_a" in "pack" to facilitate ** the calls of functions. so pack contains : ** - stack_a ** - stack_b ** - solution ** then it calls the algorithm */ t_list *sort_algo(t_stack *stack_a) { t_stack *stack_b; t_list *solution; t_list *pack; solution = ft_lstnew(NULL); if(!(stack_b = ft_calloc(1, sizeof(t_stack)))) ps_stop(stack_a, stack_b, solution, 2); pack = ft_lstnew(stack_a); ft_lstadd_back(&pack, ft_lstnew(stack_b)); ft_lstadd_back(&pack, ft_lstnew(&solution)); action(pack, sa); print_stack(stack_a); print_stack(stack_b); // 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); return (solution); }