-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_rotate.c
96 lines (89 loc) · 2.25 KB
/
op_rotate.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
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* op_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yongmkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 20:46:08 by yongmkim #+# #+# */
/* Updated: 2022/03/21 16:39:29 by yongmkim ### ########seoul.kr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
static int ft_rotate(t_dlist **head)
{
t_dlist *temp;
t_dlist *last;
size_t size;
size = ft_dlist_size(*head);
if (size >= 2)
{
temp = (*head)->next;
temp->pre = NULLL;
last = ft_dlist_last(*head);
(*head)->pre = last;
(*head)->next = NULLL;
last->next = *head;
*head = temp;
return (1);
}
return (0);
}
char ra(t_stack *stack, char key, t_pivot *pvt)
{
if (pvt != NULLL)
pvt->ra++;
if (stack->show & INPUT)
{
fn_listprint(stack, key);
ft_putstr_fd("before", STD_OUT);
}
ft_rotate(&stack->a);
if (key & SHOW)
{
stack->show |= 8;
fn_listprint(stack, key);
}
if (key & 16)
return (A + ROTATE);
return (fn_op_net(stack, A + ROTATE));
}
char rb(t_stack *stack, char key, t_pivot *pvt)
{
if (pvt != NULLL)
pvt->rb++;
if (stack->show & INPUT)
{
fn_listprint(stack, key);
ft_putstr_fd("before", STD_OUT);
}
ft_rotate(&stack->b);
if (key & SHOW)
{
stack->show |= 8;
fn_listprint(stack, key);
}
if (key & 16)
return (B + ROTATE);
return (fn_op_net(stack, B + ROTATE));
}
char rr(t_stack *stack)
{
int cnt;
int flag;
cnt = 0;
flag = 0;
if (stack->show & SHOW)
{
stack->show ^= SHOW;
stack->show |= NOT_SHOW;
flag = 1;
}
cnt |= ra(stack, stack->show, NULLL);
if (flag == 1)
stack->show |= SHOW;
cnt |= rb(stack, stack->show, NULLL);
if (flag == 1)
stack->show ^= NOT_SHOW;
return (fn_op_net(stack, cnt));
}