-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_swap.c
135 lines (117 loc) · 2.43 KB
/
push_swap.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lhenneca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/11 14:07:56 by lhenneca #+# #+# */
/* Updated: 2020/02/03 16:57:04 by lhenneca ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
char *rra(int **tab, int len)
{
rot_rev(*tab, len);
return ("rra");
}
char *ra(int **tab, int len)
{
rot(*tab, len);
return ("ra");
}
char *rrb(int **tab, int len)
{
rot_rev(*tab, len);
return ("rrb");
}
char *rb(int **tab, int len)
{
rot_rev(*tab, len);
return ("rb");
}
char *sa(int **tab, int len)
{
swap(*tab, len);
return ("sa");
}
char *sb(int **tab, int len)
{
swap(*tab, len);
return ("sb");
}
//len = max index value possible
int max(int *tab, int len)
{
int n;
n = tab[len];
while (len > 0)
{
len--;
if (n < tab[len])
n = tab[len];
}
return (n);
}
//len = max index value possible
int min(int *tab, int len)
{
int n;
n = tab[len];
while (len > 0)
{
len--;
if (n > tab[len])
n = tab[len];
}
return (n);
}
int stack_a(int **tab, int len)
{
if (len < 1)
return (0);
if (*tab[len] == max(*tab, len))
ft_putendl(rra(tab, len));
if (*tab[len] > *tab[len - 1] || *tab[len] > *tab[0])
{
if (*tab[len] > *tab[0])
ft_putendl(rra(tab, len));
else
ft_putendl(sa(tab, len));
}
return (0);
}
//len = max index value possible
int tri(int **a, int **b, int len)
{
int i;
int lena;
int lenb;
i = len - 1;
lena = len - 1;
lenb = 0;
while (i < len)
{
while (lena >= 1)
{
if (*a[lena] > *a[lena - 1])
{
swap(*a, lena);
write(1,"sa\n", 3);
lenb++;
}
if (*a[lena] < *b[lenb])
{
}
if (lenb > 0 && *b[lenb] < *b[lenb - 1])
{
swap(*b, lenb);
write(1,"sa\n", 3);
}
push(*a, *b, lena, lenb);
write(1,"pb\n", 3);
lena--;
}
}
return (i);
}