-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswap.c
59 lines (53 loc) · 1.55 KB
/
swap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mohaben- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/06 11:56:20 by mohaben- #+# #+# */
/* Updated: 2025/01/13 11:22:03 by mohaben- ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void swap(t_stack *s1, t_stack *s2)
{
int tmp;
tmp = s1->data;
s1->data = s2->data;
s2->data = tmp;
tmp = s1->index;
s1->index = s2->index;
s2->index = tmp;
}
void sa(t_list *list, int print)
{
if (!list->a)
return ;
if (list->size_a >= 2)
{
swap(list->a, list->a->next);
list->tail_a = ft_lstlast(list->a);
if (print)
write(1, "sa\n", 3);
}
}
void sb(t_list *list, int print)
{
if (!list->b)
return ;
if (list->size_b >= 2)
{
swap(list->b, list->b->next);
list->tail_b = ft_lstlast(list->b);
if (print)
write(1, "sb\n", 3);
}
}
void ss(t_list *list, int print)
{
sa(list, 0);
sb(list, 0);
if (print)
write(1, "ss\n", 3);
}