/
alg_file.c
executable file
·87 lines (78 loc) · 1.83 KB
/
alg_file.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* alg_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jadawson <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/11 19:35:19 by jadawson #+# #+# */
/* Updated: 2018/11/03 18:55:43 by jadawson ### ########.fr */
/* */
/* ************************************************************************** */
#include "check_header.h"
int push_and_find(t_nums **a, t_nums **b, int small)
{
push_b(a, b);
write(1, "pb\n", 3);
if (*a)
small = min_finder(*a, small);
return (small);
}
int push_and_i(t_nums **a, t_nums **b)
{
int i;
i = 0;
while (*b)
{
push_a(a, b);
write(1, "pa\n", 3);
i++;
}
return (i);
}
int ra_or_rra_two(t_nums **a, int tot_minus_pos, int i)
{
while (tot_minus_pos > 0)
{
reverse_rotate_a(a);
write(1, "rra\n", 4);
tot_minus_pos--;
i++;
}
return (i);
}
int ra_or_rra(t_nums **a, int tot, int pos)
{
int i;
int half;
int tot_minus_pos;
i = 0;
half = tot / 2;
tot_minus_pos = tot - pos;
if (pos <= half)
{
while (pos > 0)
{
rotate_a(a);
write(1, "ra\n", 3);
pos--;
i++;
}
}
if (pos > half)
i += ra_or_rra_two(a, tot_minus_pos, i);
return (i);
}
int pos_finder(t_nums *a, int pos, int small)
{
int i;
i = -1;
while (a)
{
i++;
if (small == a->num)
pos = i;
a = a->next;
}
return (pos);
}