data_structures
array_pop.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* array_pop.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/16 23:46:05 by unite #+# #+# */
10 /* Updated: 2020/09/07 19:59:15 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "array.h"
15 #include "array_utils.h"
16 
17 void *array_pop(t_array *array)
18 {
19  void *content;
20 
21  if (!array || array->size == 0)
22  return (NULL);
23  content = array->arr[array->size - 1];
24  array->arr[array->size - 1] = NULL;
25  array->size--;
26  if (array->size <= array->capacity / 4)
27  array_shrink(array);
28  return (content);
29 }
array.h
array_pop
void * array_pop(t_array *array)
Removes and returns the element at the end of this array.
Definition: array_pop.c:17
s_array::arr
void ** arr
The data.
Definition: array.h:51
s_array
A resizable array.
Definition: array.h:47
s_array::capacity
size_t capacity
The capacity of this array.
Definition: array.h:50
s_array::size
size_t size
The number of items in this array.
Definition: array.h:49
array_utils.h