-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilscont.c
More file actions
74 lines (63 loc) · 1.71 KB
/
utilscont.c
File metadata and controls
74 lines (63 loc) · 1.71 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* utilscont.c :+: :+: */
/* +:+ */
/* By: candace <candace@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/08/23 14:34:54 by candace #+# #+# */
/* Updated: 2022/10/17 11:45:34 by cstaats ######## odam.nl */
/* */
/* ************************************************************************** */
#include "pushswap.h"
int arraylen(int *arr)
// This works when there is no 0 element in the array
{
int cnt;
cnt = 0;
while (arr[cnt] != 0)
cnt++;
return (cnt);
}
void *ft_calloc(size_t nitems, size_t size)
{
void *pnt;
pnt = malloc(nitems * size);
if (pnt == NULL)
return (NULL);
ft_bzero(pnt, (nitems * size));
return (pnt);
}
void ft_bzero(void *s, size_t n)
{
unsigned char *cnt;
cnt = (unsigned char *)s;
while (n)
{
n--;
*cnt = 0;
cnt++;
}
}
int amisorted(int *stacka, int arraylen)
// Check to see if the numbers are sorted
{
int cnt;
cnt = 0;
while (cnt < arraylen - 1)
{
if (stacka[cnt] < stacka[cnt + 1])
cnt++;
else
return (0);
}
return (1);
}
int *createb(int *stacka)
{
int *stackb;
stackb = ft_calloc(sizeof(int), arraylen(stacka) + 1);
if (stackb == NULL)
return (NULL);
return (stackb);
}