forked from mihai-negru/c-language-data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscl_stack.h
66 lines (58 loc) · 2.36 KB
/
scl_stack.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @file scl_stack.h
* @author Mihai Negru (determinant289@gmail.com)
* @version 1.0.0
* @date 2022-06-21
*
* @copyright Copyright (C) 2022-2023 Mihai Negru <determinant289@gmail.com>
* This file is part of C-language-Data-Structures.
*
* C-language-Data-Structures is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* C-language-Data-Structures is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with C-language-Data-Structures. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef STACK_UTILS_H_
#define STACK_UTILS_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include "scl_config.h"
/**
* @brief stack Node object definition
*
*/
typedef struct stack_node_s {
void *data; /* Pointer to data */
struct stack_node_s *next; /* Pointer to next data node */
} stack_node_t;
/**
* @brief stack object definition
*
*/
typedef struct stack_s {
stack_node_t *top; /* Pointer to top data node */
free_func frd; /* Function to free one data */
size_t data_size; /* Length in bytes of the data data type */
size_t size; /* Size of the stack */
} stack_t;
stack_t* create_stack (free_func frd, size_t data_size);
scl_error_t free_stack (stack_t * const __restrict__ stack);
scl_error_t print_stack (const stack_t * const __restrict__ stack, action_func print);
uint8_t is_stack_empty (const stack_t * const __restrict__ stack);
size_t get_stack_size (const stack_t * const __restrict__ stack);
const void* stack_top (const stack_t * const __restrict__ stack);
scl_error_t stack_push (stack_t * const __restrict__ stack, const void * __restrict__ data);
scl_error_t stack_pop (stack_t * const __restrict__ stack);
#endif /* STACK_UTILS_H_ */