53 lines
1.6 KiB
C
53 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: o_ :::::: ::: */
|
|
/* reverse_rotate.c :+: / :+::+: :+: */
|
|
/* +:+ > +:++:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
|
/* Created: 2024/11/06 19:58:58 by whaffman #+#+# #+#+# #+# #+# | */
|
|
/* Updated: 2024/11/06 20:03:30 by whaffman ### ### ### ### / \ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
#include "push_swap.h"
|
|
#include <unistd.h>
|
|
|
|
void rra(t_state *state, int silent)
|
|
{
|
|
reverse_rotate(&(state->a));
|
|
if (!silent)
|
|
ft_putstr_fd("rra\n", STDOUT_FILENO);
|
|
}
|
|
|
|
void rrb(t_state *state, int silent)
|
|
{
|
|
reverse_rotate(&(state->b));
|
|
if (!silent)
|
|
ft_putstr_fd("rrb\n", STDOUT_FILENO);
|
|
}
|
|
|
|
void rrr(t_state *state, int silent)
|
|
{
|
|
reverse_rotate(&(state->a));
|
|
reverse_rotate(&(state->b));
|
|
if (!silent)
|
|
ft_putstr_fd("rrr\n", STDOUT_FILENO);
|
|
}
|
|
|
|
void reverse_rotate(t_list **stack)
|
|
{
|
|
t_list *temp;
|
|
t_list *last;
|
|
|
|
if (!*stack)
|
|
return ;
|
|
temp = *stack;
|
|
last = ft_lstlast(*stack);
|
|
while (temp->next->next)
|
|
temp = temp->next;
|
|
temp->next = NULL;
|
|
ft_lstadd_front(stack, last);
|
|
}
|