-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_utils_bis.c
executable file
·88 lines (79 loc) · 1.92 KB
/
ft_utils_bis.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils_bis.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abadidi < abadidi@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/11 18:20:32 by abadidi #+# #+# */
/* Updated: 2021/12/11 18:20:32 by abadidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void swaper(int *xp, int *yp)
{
int temp;
temp = *xp;
*xp = *yp;
*yp = temp;
}
void bubblesort(int *arr, int n)
{
int i;
int j;
int swapped;
i = 0;
while (i < n - 1)
{
swapped = 0;
j = 0;
while (j < n - i - 1)
{
if (arr[j] > arr[j + 1])
{
swaper(&arr[j], &arr[j + 1]);
swapped = 1;
}
j++;
}
if (swapped == 0)
break ;
i++;
}
}
int ft_isdigit(int c)
{
if (c >= 48 && c <= 57)
return (1);
return (0);
}
static int ft_iswhitespace(int c)
{
if (c == '\t' || c == '\r' || c == '\n'
|| c == '\v' || c == '\f' || c == ' ')
return (1);
return (0);
}
long long ft_atoi(char const *s)
{
long long nbr;
long sign;
int i;
i = 0;
sign = 1;
nbr = 0;
while (ft_iswhitespace((int)s[i]) && s[i])
i++;
if (s[i] == '-' || s[i] == '+')
{
if (s[i] == '-')
{
sign = -1;
nbr = -nbr;
}
i++;
}
while (ft_isdigit(s[i]) && s[i])
nbr = nbr * 10 + (s[i++] - 48);
return (nbr * sign);
}