-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit_qs_b_utils.c
87 lines (77 loc) · 2.11 KB
/
split_qs_b_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* :::::::: */
/* split_qs_b_utils.c :+: :+: */
/* +:+ */
/* By: sramos <sramos@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2024/04/25 16:37:59 by sramos #+# #+# */
/* Updated: 2024/04/25 18:44:21 by sramos ######## odam.nl */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int find_bigger_index_b(t_node **stack_b)
{
int chunk;
t_node *current;
t_node *bigger;
chunk = (*stack_b)->group;
current = (*stack_b)->next;
bigger = *stack_b;
while (current && current->group == chunk)
{
if (current->index > bigger->index)
bigger = current;
current = current->next;
}
return (bigger->index);
}
int find_smaller_index_b(t_node **stack_b)
{
int chunk;
t_node *current;
t_node *smaller;
chunk = (*stack_b)->group;
current = (*stack_b)->next;
smaller = *stack_b;
while (current && current->group == chunk)
{
if (current->index < smaller->index)
smaller = current;
current = current->next;
}
return (smaller->index);
}
t_node *find_newpivot_b(t_node **stack_b)
{
int pivind;
t_node *pivot;
pivind = 0;
pivind = find_smaller_index_b(stack_b) + find_bigger_index_b(stack_b);
pivot = find_pivot(stack_b, pivind);
return (pivot);
}
void ft_reverse_b(t_node **stack_b, int count_rb)
{
while (count_rb > 0)
{
ft_rrb(stack_b);
count_rb--;
}
}
int c_nodes_g(t_node **stack_b)
{
int i;
int chunk;
t_node *current;
i = 0;
current = *stack_b;
chunk = (*stack_b)->group;
while (current && current->group == chunk)
{
current = current->next;
i++;
}
i--;
return (i);
}