-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils1.c
106 lines (95 loc) · 2.09 KB
/
utils1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alouzizi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/07 00:01:20 by alouzizi #+# #+# */
/* Updated: 2022/03/17 21:36:27 by alouzizi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int map(t_node **stack, int index, char str)
{
int i;
int j;
if (str == 'h')
return (index);
else
{
i = lent(&*stack);
j = i - index ;
return (j);
}
}
int position(int data, t_node **stack_a)
{
t_node *temp1;
t_node *temp2;
t_node *last;
int i;
last = *stack_a;
while (last->next)
last = last->next;
i = 1;
temp1 = *stack_a;
temp2 = (*stack_a)->next;
while (temp2)
{
if (temp1->data < data && temp2->data > data)
return (i);
i++;
temp1 = temp1->next;
temp2 = temp2->next;
}
if (data > max(&*stack_a))
return (index_min(&*stack_a));
else if (data < min(&*stack_a))
return (index_min(&*stack_a));
else
return (0);
}
int the_big(int *s, int l)
{
int i;
int j;
i = 0;
j = s[i];
while (i < l)
{
if (j < s[i])
{
j = s[i];
}
i++;
}
return (j);
}
int the_min(int *s, int l)
{
int i;
int j;
i = 0;
j = s[i];
while (i < l)
{
if (j > s[i])
j = s[i];
i++;
}
free(s);
return (j);
}
int *long_subscoince(int *arr, int n, int *l)
{
int *lis;
int *prev;
lis = malloc(sizeof(int) * n);
prev = malloc(sizeof(int) * n);
long_subscoince_2(arr, n, &prev, &lis);
prev[0] = max_index(lis, n);
*l = the_big(lis, n);
free(lis);
return (prev);
}