-
Notifications
You must be signed in to change notification settings - Fork 0
/
radix_utils.c
91 lines (80 loc) · 1.85 KB
/
radix_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
88
89
90
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* radix_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ikayacio <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/20 11:37:25 by ikayacio #+# #+# */
/* Updated: 2023/06/20 11:39:47 by ikayacio ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void make_index(t_list **a)
{
long index;
long min;
t_list *temp;
temp = *a;
index = 0;
min = find_min2(*a, index);
while (min != 0)
{
while (temp -> content != min && temp != NULL)
temp = temp -> next;
if (temp != NULL)
{
index++;
temp -> content = index;
temp = *a;
}
min = find_min2(*a, index);
}
}
void make_positive(t_list **a)
{
t_list *temp;
long min;
min = find_min(*a);
temp = *a;
while (temp)
{
temp -> content -= min;
temp = temp -> next;
}
make_index(a);
}
void right_shift(t_list **a)
{
t_list *temp;
temp = *a;
while (temp)
{
temp->content = (temp->content >> 1);
temp = temp->next;
}
}
int has_lastbit_zero(t_list *a)
{
t_list *temp;
temp = a;
while (temp)
{
if ((temp -> content & 1) == 0)
return (1);
temp = temp -> next;
}
return (0);
}
int all_zero(t_list *a)
{
t_list *temp;
temp = a;
while (temp)
{
if (temp -> content != 0)
return (0);
temp = temp -> next;
}
return (1);
}