-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk_sort_utils.c
72 lines (64 loc) · 1.14 KB
/
chunk_sort_utils.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
#include "push_swap.h"
int32_t left_bigger_p(t_stack *b, int32_t chunk, int32_t p)
{
t_stack *tmp;
int32_t chunk_b;
if (!b)
return (0);
tmp = b;
chunk_b = tmp->chunk_b;
while (tmp && tmp->chunk == chunk && tmp->chunk_b == chunk_b)
{
if (tmp->index > p)
return (1);
tmp = tmp->next;
}
return (0);
}
int32_t chunk_length(t_stack *stack, int32_t chunk)
{
t_stack *tmp;
int32_t len;
int32_t chunk_b;
if (!stack || stack->chunk != chunk)
return (0);
len = 0;
tmp = stack;
chunk_b = tmp->chunk_b;
while (tmp && tmp->chunk == chunk && tmp->chunk_b == chunk_b)
{
++len;
tmp = tmp->next;
}
return (len);
}
int32_t left_less_p_ch(t_stack *a, int32_t chunk, int32_t p)
{
t_stack *tmp;
int32_t chunk_b;
if (!a)
return (0);
tmp = a;
chunk_b = a->chunk_b;
while (tmp && tmp->chunk == chunk && tmp->chunk_b == chunk_b)
{
if (tmp->index <= p)
return (1);
tmp = tmp->next;
}
return (0);
}
int32_t find_next_index(t_stack *stack, int32_t chunk)
{
t_stack *tmp;
int32_t max;
tmp = stack;
max = 0;
while (tmp && tmp->chunk == chunk)
{
if (tmp->index > max)
max = tmp->index;
tmp = tmp->next;
}
return (max);
}