Push_swap/checker_folder/checker_process.c
2022-01-19 04:01:40 +01:00

93 lines
2.2 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 "../Utils/push_swap.h"
int sa_sb(t_list **list, t_slist **process, char type, int set)
{
t_list *swap;
if (!(*list) || !(*list)->next)
return (1);
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"));
}
return (1);
}
int ra_rb(t_list **list, t_slist **process, char type)
{
t_list *swap;
if (!(*list) || !(*list)->next)
return (1);
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"));
return (1);
}
int pa(t_list **list_a, t_list **list_b, t_slist **process)
{
t_list *swap;
if (!(*list_b))
return (1);
swap = *list_b;
*list_b = (*list_b)->next;
ft_lstadd_front(list_a, swap);
s_lstadd_back(process, new_slist("pa"));
return (1);
}
int pb(t_list **list_a, t_list **list_b, t_slist **process)
{
t_list *swap;
if (!(*list_a))
return (1);
swap = *list_a;
*list_a = (*list_a)->next;
ft_lstadd_front(list_b, swap);
s_lstadd_back(process, new_slist("pb"));
return (1);
}
int rra_rrb(t_list **list, t_slist **process, char type)
{
t_list *swap;
if (!(*list) || !(*list)->next)
return (1);
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"));
return (1);
}