data_structures
src
data_structures
list
list_peek.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* list_peek.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/18 23:15:24 by unite #+# #+# */
10
/* Updated: 2020/09/07 22:01:07 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
list.h
"
15
16
void
*
list_peek
(
const
t_list
*alst,
size_t
index)
17
{
18
t_link
*link;
19
20
if
(index >= alst->
size
)
21
ds_exit_set
(EINVAL);
22
link = alst->
head
;
23
while
(index-- > 0)
24
link = link->
next
;
25
return
(link->
content
);
26
}
s_link::content
void * content
The content.
Definition:
list.h:36
s_list::head
t_link * head
The first link.
Definition:
list.h:56
s_list
Doubly-linked list of generic items.
Definition:
list.h:54
s_list::size
size_t size
The number of items in the list.
Definition:
list.h:58
list_peek
void * list_peek(const t_list *alst, size_t index)
Returns the item at the specified position in the list.
Definition:
list_peek.c:16
s_link::next
struct s_link * next
The next link.
Definition:
list.h:37
list.h
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
s_link
A link in a doubly-linked list.
Definition:
list.h:34
Generated by
1.8.16