-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplelogic3.c
75 lines (64 loc) · 1.91 KB
/
simplelogic3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simplelogic3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgerda <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/23 19:01:18 by bgerda #+# #+# */
/* Updated: 2020/02/23 19:03:01 by bgerda ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int oddeven(int len)
{
int res;
res = 0;
if (len % 2 != 0)
res = len / 2;
if (len % 2 == 0)
res = (len / 2) - 1;
return (res);
}
void rot_push(t_stack *stack_a, t_stack *stack_b, int len)
{
t_properties *counters;
counters = stack_b->prop;
counters->count_push = oddeven(len);
counters->var = head_part(stack_b);
rotnpush(stack_b, stack_a, gt);
}
void push_rot(t_stack *stack_a, t_stack *stack_b)
{
t_properties *counters;
counters = stack_b->prop;
counters->count_push = 3;
counters->var = find_min(stack_b);
rotnpush(stack_b, stack_a, gt);
}
int find_min(t_stack *stack)
{
int min;
int range;
t_node *tmp;
tmp = stack->head;
range = tmp->range;
min = tmp->data;
while (tmp && tmp->range == range)
{
if (tmp->data < min)
min = tmp->data;
tmp = tmp->next;
}
return (min);
}
int half_push(t_stack *stack_a, t_stack *stack_b)
{
int len;
len = len_range(stack_b, stack_b->head->range);
if (len == 4)
push_rot(stack_a, stack_b);
if (len > 4)
rot_push(stack_a, stack_b, len);
return (0);
}