data_structures
array_swap.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* array_swap.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/17 14:18:30 by unite #+# #+# */
10 /* Updated: 2020/09/07 21:49:52 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "array.h"
15 
16 void array_swap(t_array *array, size_t ind1, size_t ind2)
17 {
18  void *content;
19 
20  if (!array || ind1 >= array_size(array) || ind2 >= array_size(array))
21  ds_exit_set(EINVAL);
22  content = array->arr[ind1];
23  array->arr[ind1] = array->arr[ind2];
24  array->arr[ind2] = content;
25 }
array_size
size_t array_size(const t_array *array)
Returns the number of elements in this array.
Definition: array_size.c:16
array.h
array_swap
void array_swap(t_array *array, size_t ind1, size_t ind2)
Swaps elements at the two specified positions in the array.
Definition: array_swap.c:16
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