-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_radixsort.c
55 lines (50 loc) · 1.45 KB
/
ft_radixsort.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_radixsort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: javellis <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/27 18:04:27 by javellis #+# #+# */
/* Updated: 2023/01/31 16:54:19 by javellis ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_radixsort2(int size, int i, t_stack **top, t_stack **b)
{
int j;
j = 0;
while (j < size && *top)
{
if ((((*top)->val >> i) & 1) == 1)
{
ft_printf("ra\n");
ft_rotate(top);
}
else
{
ft_printf("pb\n");
ft_push(top, b);
}
j++;
}
}
void ft_radixsort(t_stack **a, t_stack **b)
{
int i;
int size;
t_stack *top;
size = ft_lstsize((t_list *)*a);
i = -1;
top = *a;
while (++i < ft_maxbits(size - 1))
{
ft_radixsort2(size, i, &top, b);
while ((*b) != NULL)
{
ft_printf("pa\n");
ft_push(b, &top);
}
}
*a = top;
}