-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_b.c
83 lines (74 loc) Β· 1.91 KB
/
rules_b.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rules_b.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahajji <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/22 15:30:10 by ahajji #+# #+# */
/* Updated: 2023/02/01 15:31:10 by ahajji ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void rb(t_list **lst)
{
t_list *node;
t_list *last_node;
if (ft_lstsize(*lst) < 2)
return ;
node = *lst;
last_node = ft_lstlast(*lst);
*lst = (*lst)->next;
last_node->next = node;
node->next = NULL;
printf("rb\n");
}
void rrb(t_list **lst)
{
t_list *node;
t_list *last_node;
t_list *head;
head = *lst;
last_node = ft_lstlast(*lst);
node = ft_beforlast(*lst);
node->next = NULL;
last_node->next = head;
*lst = last_node;
printf("rrb\n");
}
void sb(t_list **lst)
{
t_list *head;
t_list *tmp;
t_list *tmp_2;
head = *lst;
tmp = (*lst)->next;
tmp_2 = tmp->next;
*lst = tmp;
(*lst)->next = head;
head->next = tmp_2;
printf("sb\n");
}
void pb(t_list **lst, t_list **s_lst, t_data *data)
{
t_list *top;
t_list *last_node;
t_list *node;
if (*lst == NULL)
return ;
top = *lst;
*lst = (*lst)->next;
if (*s_lst == NULL)
{
*s_lst = top;
(*s_lst)->next = NULL;
printf("pb\n");
return ;
}
node = *s_lst;
*s_lst = top;
(*s_lst)->next = node;
data->num_arg--;
data->count_arg--;
printf("pb\n");
}