-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_big_stack.c
59 lines (54 loc) · 1.56 KB
/
sort_big_stack.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort_big_stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dvan-der <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/15 08:15:33 by dvan-der #+# #+# */
/* Updated: 2021/12/15 08:15:34 by dvan-der ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void sort_big_stack(t_stack **a, t_stack **b, int numbers)
{
int i;
int largest_index;
int iterations;
largest_index = find_big_nbr(*a, numbers);
i = 32;
while (largest_index >= 0)
{
iterations = numbers;
while (iterations > 0)
{
if (((*a)->b_nbr)[i] == '0')
execute_p(a, b, 'b');
else if (((*a)->b_nbr)[i] == '1')
execute_r(a, 'a');
iterations--;
}
while (*b)
execute_p(a, b, 'a');
largest_index--;
i--;
}
}
int find_big_nbr(t_stack *a, int largest_nbr)
{
int i;
while (a)
{
if (a->d_nbr == largest_nbr)
break ;
a = a->next;
}
i = 0;
while (i < 32)
{
if ((a->b_nbr)[i] == '1')
break ;
i++;
}
return (32 - i);
}