norm && started mini mouv
This commit is contained in:
40
src/operations/ft_pushstack.c
Normal file
40
src/operations/ft_pushstack.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_pushstack.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/08 18:08:51 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 15:10:03 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../push_swap.h"
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_push_a(t_stack **stack_a, t_stack **stack_b)
|
||||
{
|
||||
t_stack *tmp_a;
|
||||
|
||||
if (!stack_b || !(*stack_b))
|
||||
return ;
|
||||
ft_putendl_fd("pa", STDOUT_FILENO);
|
||||
tmp_a = *stack_b;
|
||||
*stack_b = (*stack_b)->next;
|
||||
tmp_a->next = *stack_a;
|
||||
*stack_a = tmp_a;
|
||||
}
|
||||
|
||||
void ft_push_b(t_stack **stack_a, t_stack **stack_b)
|
||||
{
|
||||
t_stack *tmp_b;
|
||||
|
||||
if (!stack_a || !(*stack_a))
|
||||
return ;
|
||||
ft_putendl_fd("pb", STDOUT_FILENO);
|
||||
tmp_b = *stack_a;
|
||||
*stack_a = (*stack_a)->next;
|
||||
tmp_b->next = *stack_b;
|
||||
*stack_b = tmp_b;
|
||||
}
|
54
src/operations/ft_reverserotate.c
Normal file
54
src/operations/ft_reverserotate.c
Normal file
@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_reverserotate.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/13 13:41:25 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 15:10:13 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../push_swap.h"
|
||||
|
||||
void ft_reverserotate(t_stack **stack)
|
||||
{
|
||||
t_stack *bfrlast;
|
||||
t_stack *last;
|
||||
t_stack *stack_start;
|
||||
|
||||
bfrlast = ft_stackbeforelast(*stack);
|
||||
last = ft_stacklast(*stack);
|
||||
bfrlast->next = NULL;
|
||||
stack_start = (*stack);
|
||||
(*stack) = last;
|
||||
(*stack)->next = stack_start;
|
||||
}
|
||||
|
||||
void ft_reverserotate_a(t_stack **stack_a)
|
||||
{
|
||||
if (!stack_a || !(*stack_a) || !(*stack_a)->next)
|
||||
return ;
|
||||
ft_putendl_fd("rra", STDOUT_FILENO);
|
||||
ft_reverserotate(stack_a);
|
||||
}
|
||||
|
||||
void ft_reverserotate_b(t_stack **stack_b)
|
||||
{
|
||||
if (!stack_b || !(*stack_b) || !(*stack_b)->next)
|
||||
return ;
|
||||
ft_putendl_fd("rrb", STDOUT_FILENO);
|
||||
ft_reverserotate(stack_b);
|
||||
}
|
||||
|
||||
void ft_reverserotate_r(t_stack **stack_a, t_stack **stack_b)
|
||||
{
|
||||
if (!stack_a || !(*stack_a) || !(*stack_a)->next)
|
||||
return ;
|
||||
if (!stack_b || !(*stack_b) || !(*stack_b)->next)
|
||||
return ;
|
||||
ft_putendl_fd("rrr", STDOUT_FILENO);
|
||||
ft_reverserotate(stack_a);
|
||||
ft_reverserotate(stack_b);
|
||||
}
|
54
src/operations/ft_rotatestack.c
Normal file
54
src/operations/ft_rotatestack.c
Normal file
@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_rotatestack.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/13 12:53:55 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 15:09:40 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../push_swap.h"
|
||||
|
||||
void ft_rotatestack(t_stack **stack)
|
||||
{
|
||||
t_stack *tmp_last;
|
||||
t_stack *start;
|
||||
|
||||
if (!stack || !(*stack))
|
||||
return ;
|
||||
start = (*stack)->next;
|
||||
tmp_last = ft_stacklast(*stack);
|
||||
tmp_last->next = *stack;
|
||||
(*stack)->next = NULL;
|
||||
(*stack) = start;
|
||||
}
|
||||
|
||||
void ft_rotatestack_a(t_stack **stack_a)
|
||||
{
|
||||
if (!stack_a || !(*stack_a) || !(*stack_a)->next)
|
||||
return ;
|
||||
ft_putendl_fd("ra", STDOUT_FILENO);
|
||||
ft_rotatestack(stack_a);
|
||||
}
|
||||
|
||||
void ft_rotatestack_b(t_stack **stack_b)
|
||||
{
|
||||
if (!stack_b || !(*stack_b) || !(*stack_b)->next)
|
||||
return ;
|
||||
ft_putendl_fd("rb", STDOUT_FILENO);
|
||||
ft_rotatestack(stack_b);
|
||||
}
|
||||
|
||||
void ft_rotatestack_r(t_stack **stack_a, t_stack **stack_b)
|
||||
{
|
||||
if (!stack_a || !(*stack_a) || !(*stack_a)->next)
|
||||
return ;
|
||||
if (!stack_b || !(*stack_b) || !(*stack_b)->next)
|
||||
return ;
|
||||
ft_putendl_fd("rr", STDOUT_FILENO);
|
||||
ft_rotatestack(stack_a);
|
||||
ft_rotatestack(stack_b);
|
||||
}
|
49
src/operations/ft_swapstack.c
Normal file
49
src/operations/ft_swapstack.c
Normal file
@ -0,0 +1,49 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_swapstack.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/08 17:55:21 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/11 15:09:06 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../push_swap.h"
|
||||
|
||||
void ft_swapstack(t_stack *stack)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (!stack)
|
||||
return ;
|
||||
tmp = stack->nb;
|
||||
stack->nb = stack->next->nb;
|
||||
stack->next->nb = tmp;
|
||||
}
|
||||
|
||||
void ft_swap_a(t_stack *stack_a)
|
||||
{
|
||||
if (!stack_a)
|
||||
return ;
|
||||
ft_putendl_fd("sa", STDOUT_FILENO);
|
||||
ft_swapstack(stack_a);
|
||||
}
|
||||
|
||||
void ft_swap_b(t_stack *stack_b)
|
||||
{
|
||||
if (!stack_b)
|
||||
return ;
|
||||
ft_putendl_fd("sb", STDOUT_FILENO);
|
||||
ft_swapstack(stack_b);
|
||||
}
|
||||
|
||||
void ft_stack_ss(t_stack *stack_a, t_stack *stack_b)
|
||||
{
|
||||
if (!stack_a || !stack_b)
|
||||
return ;
|
||||
ft_putendl_fd("ss", STDOUT_FILENO);
|
||||
ft_swapstack(stack_a);
|
||||
ft_swapstack(stack_b);
|
||||
}
|
Reference in New Issue
Block a user