data_structures
stack.h
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* stack.h :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/16 17:19:03 by unite #+# #+# */
10 /* Updated: 2020/09/07 22:19:38 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #ifndef STACK_H
15 
16 # define STACK_H
17 
18 # include <errno.h>
19 # include <sys/types.h>
20 # include "types.h"
21 # include "array.h"
22 # include "utils.h"
23 
29 typedef t_array t_stack;
30 
36 void stack_push(t_stack *stack, const void *data);
37 
43 void *stack_pop(t_stack *stack);
44 
50 void *stack_peek(const t_stack *stack);
51 
56 void stack_delete(t_stack *stack);
57 
63 size_t stack_size(const t_stack *stack);
64 
71 t_stack *stack_new(const t_type *type);
72 
78 t_stack *stack_copy(const t_stack *stack);
79 
80 #endif
types.h
stack_copy
t_stack * stack_copy(const t_stack *stack)
Copies a stack and all it contents.
Definition: stack_copy.c:16
stack_pop
void * stack_pop(t_stack *stack)
Removed and returns the item most recently added to this stack.
Definition: stack_pop.c:16
array.h
stack_delete
void stack_delete(t_stack *stack)
Deletes the stack and frees memory taken by its contents.
Definition: stack_delete.c:16
utils.h
stack_size
size_t stack_size(const t_stack *stack)
Returns the number of items in this stack.
Definition: stack_size.c:16
stack_peek
void * stack_peek(const t_stack *stack)
Returns the item most recently added to this stack, without removing it.
Definition: stack_peek.c:16
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
s_array
A resizable array.
Definition: array.h:47
stack_push
void stack_push(t_stack *stack, const void *data)
Copy the item and add it to the stack.
Definition: stack_push.c:16
t_stack
t_array t_stack
A last-in-first-out stack of generic items.
Definition: stack.h:29
stack_new
t_stack * stack_new(const t_type *type)
Initializes an empty stack.
Definition: stack_new.c:16