-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.c
72 lines (62 loc) · 1.85 KB
/
operations.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* operations.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhlim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 12:51:37 by zhlim #+# #+# */
/* Updated: 2023/08/05 14:34:01 by zhlim ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void swap(t_list **stack)
{
t_list *tmp;
tmp = (*stack)->next;
if (!tmp)
return ;
(*stack)->next = tmp->next;
tmp->next = *stack;
*stack = tmp;
}
void push(t_list **stack_pop, t_list **stack_push, char *str)
{
t_list *tmp;
if (!*stack_pop)
return ;
tmp = *stack_pop;
*stack_pop = (*stack_pop)->next;
tmp->next = NULL;
ft_lstadd_front(stack_push, tmp);
ft_printf(str);
}
void rotate(t_list **stack)
{
t_list *tmp;
if (!*stack || !(*stack)->next)
return ;
tmp = *stack;
*stack = (*stack)->next;
tmp->next = NULL;
ft_lstadd_back(stack, tmp);
}
void reverse_rotate(t_list **stack)
{
t_list *last;
t_list *tmp;
if (!*stack || !(*stack)->next)
return ;
last = ft_lstlast(*stack);
tmp = *stack;
while (tmp->next != last)
tmp = tmp->next;
tmp->next = NULL;
ft_lstadd_front(stack, last);
}
void double_reverse_rotate(t_list **stack_a, t_list **stack_b, char *str)
{
reverse_rotate(stack_a);
reverse_rotate(stack_b);
ft_printf(str);
}