push et swap fonctionnent

This commit is contained in:
hugogogo
2021-06-15 14:27:55 +02:00
parent aeb5b57725
commit dc99227f94
12 changed files with 61 additions and 55 deletions

View File

@@ -1,29 +1,36 @@
#include "push_swap.h"
t_list *sa(t_stack **stack, t_list **solution)
void swap(t_stack **stack)
{
t_stack *a;
int tmp;
t_stack *tmp;
a = *stack;
if (!a->next)
return (NULL);
tmp = a->n;
a->n = a->next->n;
a->next->n = tmp;
fill_solution(solution, ft_strdup("sa"));
tmp = *stack;
if (!(tmp->next))
return ;
*stack = (*stack)->next;
tmp->next = (*stack)->next;
(*stack)->next = tmp;
}
t_list *sa(t_stack **a, t_list **solution)
{
swap(a);
fill_solution(*solution, ft_strdup("sa"));
return (NULL);
}
t_list *sb(t_stack **b, t_list **solution)
{
return (sa(b, solution));
swap(b);
fill_solution(*solution, ft_strdup("sb"));
return (NULL);
}
t_list *ss(t_stack **a, t_stack **b, t_list **solution)
{
sa(a, solution);
sa(b, solution);
swap(a);
swap(b);
fill_solution(*solution, ft_strdup("sb"));
return (NULL);
}