push et swap fonctionnent
This commit is contained in:
43
srcs/push.c
43
srcs/push.c
@@ -1,37 +1,28 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void push(t_stack **dst, t_stack **src)
|
||||
{
|
||||
t_stack *tmp1;
|
||||
t_stack *tmp2;
|
||||
|
||||
tmp1 = *src;
|
||||
tmp2 = *dst;
|
||||
*src = (*src)->next;
|
||||
tmp1->next = tmp2;
|
||||
*dst = tmp1;
|
||||
}
|
||||
|
||||
t_list *pa(t_stack **a, t_stack **b, t_list **solution)
|
||||
{
|
||||
t_stack *tmp;
|
||||
|
||||
if (!(tmp = ft_calloc(1, sizeof(t_stack))))
|
||||
ps_stop(*a, *b, *solution, 2);
|
||||
tmp->n = (*b)->n;
|
||||
tmp->next = NULL;
|
||||
(*a)->next = tmp;
|
||||
fill_solution(solution, ft_strdup("pa"));
|
||||
push(a, b);
|
||||
fill_solution(*solution, ft_strdup("pa"));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *pb(t_stack **dst, t_stack **src, t_list **solution)
|
||||
t_list *pb(t_stack **b, t_stack **a, t_list **solution)
|
||||
{
|
||||
t_stack *a;
|
||||
t_stack *b;
|
||||
t_stack *tmp;
|
||||
|
||||
a = *src;
|
||||
b = *dst;
|
||||
|
||||
if (!(b = ft_calloc(1, sizeof(t_stack))))
|
||||
ps_stop(a, b, *solution, 2);
|
||||
b->n = a->n;
|
||||
b->next = NULL;
|
||||
|
||||
tmp = a->next;
|
||||
a->n = a->next->n;
|
||||
a->next = a->next->next;
|
||||
free(tmp);
|
||||
fill_solution(solution, ft_strdup("pa"));
|
||||
push(b, a);
|
||||
fill_solution(*solution, ft_strdup("pb"));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user