81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* process.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/01/17 11:52:37 by apommier #+# #+# */
|
|
/* Updated: 2022/01/17 11:52:37 by apommier ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "push_swap.h"
|
|
|
|
void ft_sa_sb(t_list **list, t_slist **process, char type, int set)
|
|
{
|
|
t_list *swap;
|
|
|
|
swap = (*list)->next->next;
|
|
(*list)->next->next = *list;
|
|
*list = (*list)->next;
|
|
(*list)->next->next = swap;
|
|
if (set)
|
|
{
|
|
if (type == 'a')
|
|
s_lstadd_back(process, new_slist("sa"));
|
|
else if (type == 'b')
|
|
s_lstadd_back(process, new_slist("sb"));
|
|
}
|
|
}
|
|
|
|
void ft_ra_rb(t_list **list, t_slist **process, char type)
|
|
{
|
|
t_list *swap;
|
|
|
|
swap = *list;
|
|
(ft_lstlast(*list))->next = *list;
|
|
*list = (*list)->next;
|
|
swap->next = 0;
|
|
if (type == 'a')
|
|
s_lstadd_back(process, new_slist("ra"));
|
|
else if (type == 'b')
|
|
s_lstadd_back(process, new_slist("rb"));
|
|
}
|
|
|
|
t_list *ft_pa(t_list **list_a, t_list **list_b, t_slist **process)
|
|
{
|
|
t_list *swap;
|
|
|
|
swap = *list_b;
|
|
*list_b = (*list_b)->next;
|
|
ft_lstadd_front(list_a, swap);
|
|
s_lstadd_back(process, new_slist("pa"));
|
|
return (*list_b);
|
|
}
|
|
|
|
void ft_pb(t_list **list_a, t_list **list_b, t_slist **process)
|
|
{
|
|
t_list *swap;
|
|
|
|
swap = *list_a;
|
|
*list_a = (*list_a)->next;
|
|
ft_lstadd_front(list_b, swap);
|
|
s_lstadd_back(process, new_slist("pb"));
|
|
}
|
|
|
|
void ft_rra_rrb(t_list **list, t_slist **process, char type)
|
|
{
|
|
t_list *swap;
|
|
|
|
if (!(*list)->next)
|
|
return ;
|
|
swap = ft_lstlast(*list);
|
|
ft_lstbeforelast(*list)->next = 0;
|
|
ft_lstadd_front(list, swap);
|
|
if (type == 'a')
|
|
s_lstadd_back(process, new_slist("rra"));
|
|
else if (type == 'b')
|
|
s_lstadd_back(process, new_slist("rrb"));
|
|
}
|