mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* push.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/12/08 15:09:40 by mteriier #+# #+# */
|
|
/* Updated: 2026/01/08 13:52:01 by dgaillet ### ########lyon.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "push_swap.h"
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
void pa(t_stacks *stacks)
|
|
{
|
|
t_stack *b_push;
|
|
|
|
if (!stacks || !stacks->b)
|
|
return ;
|
|
b_push = stacks->b;
|
|
if (stacks->b->next == stacks->b)
|
|
stacks->b = NULL;
|
|
else
|
|
{
|
|
stacks->b->next->previous = stacks->b->previous;
|
|
stacks->b->previous->next = stacks->b->next;
|
|
stacks->b = stacks->b->next;
|
|
}
|
|
stack_add_front(&(stacks->a), b_push);
|
|
if (stacks->bench)
|
|
stacks->pa++;
|
|
else
|
|
write(1, "pa\n", 3);
|
|
}
|
|
|
|
void pb(t_stacks *stacks)
|
|
{
|
|
t_stack *a_push;
|
|
|
|
if (!stacks || !stacks->a)
|
|
return ;
|
|
a_push = stacks->a;
|
|
if (stacks->a->next == stacks->a)
|
|
stacks->a = NULL;
|
|
else
|
|
{
|
|
stacks->a->next->previous = stacks->a->previous;
|
|
stacks->a->previous->next = stacks->a->next;
|
|
stacks->a = stacks->a->next;
|
|
}
|
|
stack_add_front(&(stacks->b), a_push);
|
|
if (stacks->bench)
|
|
stacks->pb++;
|
|
else
|
|
write(1, "pb\n", 3);
|
|
}
|