push et swap fonctionnent
This commit is contained in:
33
srcs/swap.c
33
srcs/swap.c
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user