data_structures
src
data_structures
array
array_sorted.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* array_sorted.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/19 17:00:37 by unite #+# #+# */
10
/* Updated: 2020/09/07 21:50:05 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
array.h
"
15
16
int
array_sorted
(
const
t_array
*array)
17
{
18
size_t
i;
19
20
if
(array->
type
->
cmp
== NULL)
21
ds_exit_set
(ENOTSUP);
22
i = 0;
23
while
(i < array->size - 1)
24
{
25
if
(array->
type
->
cmp
(array->
arr
[i], array->
arr
[i + 1]) > 0)
26
return
(0);
27
i++;
28
}
29
return
(1);
30
}
array_sorted
int array_sorted(const t_array *array)
Checks if an array is sorted in ascending order.
Definition:
array_sorted.c:16
s_type::cmp
int(* cmp)(const void *, const void *)
(optional) A function ponter used to compare members of this data type
Definition:
types.h:52
array.h
s_array::type
const t_type * type
The type of items in this array.
Definition:
array.h:52
s_array::arr
void ** arr
The data.
Definition:
array.h:51
s_array
A resizable array.
Definition:
array.h:47
ds_exit_set
void ds_exit_set(int err)
Set errno to the specified value, print the error message, and exit the process.
Definition:
ds_exit_set.c:22
Generated by
1.8.16