-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplelogic2.c
73 lines (64 loc) · 2 KB
/
simplelogic2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simplelogic2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgerda <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/23 18:58:05 by bgerda #+# #+# */
/* Updated: 2020/02/23 19:00:35 by bgerda ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int desc(int a, int b)
{
if (a > b)
return (0);
return (1);
}
void push_rot_a(t_stack *stack_a, t_stack *stack_b)
{
t_properties *counters;
counters = stack_a->prop;
counters->count_push = 1;
counters->var = find_min(stack_a);
rotnpush(stack_a, stack_b, eq);
revrota(stack_a);
}
void pushtob(t_stack *stack_a, t_stack *stack_b)
{
t_node *tmp;
t_properties *counters;
tmp = stack_a->head;
counters = stack_a->prop;
while (tmp->data < counters->midpoint && counters->count_push)
{
p_ab(stack_a, stack_b, counters->midpoint);
tmp = stack_a->head;
}
}
void pushtoa(t_stack *stack_a, t_stack *stack_b)
{
int part;
t_node *tmp;
tmp = stack_a->head;
part = tmp->range;
while (tmp && tmp->range == part)
{
p_ab(stack_a, stack_b, part);
tmp = stack_a->head;
}
}
void sort_stack(t_stack *stack, int (*f)(int, int))
{
rerange(stack);
if (!is_sort(stack, f))
{
if (stack->size == 3 && stack->prop->name == 'a')
lasthree(stack, find_min(stack));
else if (len_range(stack, stack->head->range) == 2)
s_ab(stack);
else if (len_range(stack, stack->head->range) > 2)
instr_sort(stack);
}
}