-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch_deque_push_pop_bonus.c
43 lines (38 loc) · 1.51 KB
/
ch_deque_push_pop_bonus.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ch_deque_push_pop_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nkawaguc <nkawaguc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/20 12:23:38 by nkawaguc #+# #+# */
/* Updated: 2024/10/20 17:44:28 by nkawaguc ### ########.fr */
/* */
/* ************************************************************************** */
#include "ch_deque_bonus.h"
void deque_push_front(t_deque *deque, int value)
{
if (!deque)
return ;
deque->head = (deque->head + 1) % deque->limit;
deque->data[deque->head] = value;
}
void deque_push_back(t_deque *deque, int value)
{
if (!deque)
return ;
deque->tail = (deque->tail - 1 + deque->limit) % deque->limit;
deque->data[deque->tail] = value;
}
void deque_pop_front(t_deque *deque)
{
if (!deque || deque_empty(deque))
return ;
deque->head = (deque->head - 1 + deque->limit) % deque->limit;
}
void deque_pop_back(t_deque *deque)
{
if (!deque || deque_empty(deque))
return ;
deque->tail = (deque->tail + 1) % deque->limit;
}