-
Notifications
You must be signed in to change notification settings - Fork 0
/
instructions_1.c
83 lines (73 loc) · 2.14 KB
/
instructions_1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instructions_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akaratas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/10 16:43:09 by akaratas #+# #+# */
/* Updated: 2024/03/20 15:45:10 by akaratas ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void swap_a(t_list *lst)
{
int top1;
int top2;
int flag1;
int flag2;
if (ft_lstsize(lst) <= 1)
return ;
top1 = lst->content;
top2 = (lst->next)->content;
flag1 = lst->flag;
flag2 = (lst->next)->flag;
lst->content = top2;
(lst->next)->content = top1;
lst->flag = flag2;
(lst->next)->flag = flag1;
write(1, "sa\n", 3);
}
void swap_b(t_list *lst)
{
int top1;
int top2;
int flag1;
int flag2;
if (ft_lstsize(lst) <= 1)
return ;
top1 = lst->content;
top2 = (lst->next)->content;
flag1 = lst->flag;
flag2 = (lst->next)->flag;
lst->content = top2;
(lst->next)->content = top1;
lst->flag = flag2;
(lst->next)->flag = flag1;
write(1, "sb\n", 3);
}
void swap_ab(t_list *stack_a, t_list *stack_b)
{
swap_a(stack_a);
swap_a(stack_b);
}
void push_a(t_list **stack_ap, t_list **stack_bp)
{
t_list *top_b;
if (stack_ap == NULL || stack_bp == NULL || *stack_bp == NULL)
return ;
top_b = *stack_bp;
*stack_bp = (*stack_bp)->next;
ft_lstadd_front(stack_ap, top_b);
write(1, "pa\n", 3);
}
void push_b(t_list **stack_ap, t_list **stack_bp)
{
t_list *top_a;
if (stack_ap == NULL || stack_bp == NULL || *stack_ap == NULL)
return ;
top_a = *stack_ap;
*stack_ap = (*stack_ap)->next;
ft_lstadd_front(stack_bp, top_a);
write(1, "pb\n", 3);
}