done
This commit is contained in:
parent
1f5c92e0b0
commit
bf24b5da96
37
indexing.c
37
indexing.c
@ -1,37 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* indexing.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/01/05 03:23:29 by apommier #+# #+# */
|
|
||||||
/* Updated: 2022/01/05 03:23:29 by apommier ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "push_swap.h"
|
|
||||||
|
|
||||||
void lst_indexing(t_list *list)
|
|
||||||
{
|
|
||||||
int index;
|
|
||||||
t_list *swap;
|
|
||||||
t_list *save;
|
|
||||||
|
|
||||||
swap = list;
|
|
||||||
save = list;
|
|
||||||
index = 0;
|
|
||||||
while (save)
|
|
||||||
{
|
|
||||||
index = 1;
|
|
||||||
while (swap)
|
|
||||||
{
|
|
||||||
if (*(int *)save->nbr > *(int *)swap->nbr)
|
|
||||||
index++;
|
|
||||||
swap = swap->next;
|
|
||||||
}
|
|
||||||
save->index = index;
|
|
||||||
swap = list;
|
|
||||||
save = save->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
78
process.c
78
process.c
@ -1,78 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user