-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
123 lines (107 loc) · 2.52 KB
/
stack.h
File metadata and controls
123 lines (107 loc) · 2.52 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* ================================================
*
* Copyright 2017-2025 Manoel Vilela
*
* Author: Manoel Vilela
* Contact: manoel_vilela@engineer.com
* Organization: UFC
*
* ===============================================
*/
#ifndef STACK_H
#define STACK_H
#define STACK_STATIC_MAX 10
#include "../iterator/iterator.h"
/**
* @brief A stack data structure.
*/
typedef struct stack Stack;
/**
* @brief Creates an empty stack.
*
* @return A pointer to the new stack.
* @ingroup DataStructureMethods
*/
Stack* stack_create(void);
/**
* @brief Checks if a stack is empty.
*
* @param s The stack to check.
* @return 1 if the stack is empty, 0 otherwise.
* @ingroup DataStructureMethods
*/
int stack_empty(Stack* s);
/**
* @brief Pushes an element onto the top of a stack.
*
* @param s The stack to push onto.
* @param data The data to push.
* @ingroup DataStructureMethods
*/
void stack_push(Stack* s, int data);
/**
* @brief Pops an element from the top of a stack.
*
* @param s The stack to pop from.
* @return The popped element.
* @ingroup DataStructureMethods
*/
int stack_pop(Stack* s);
/**
* @brief Check if element is on the stack.
*
* @param s The stack to check.
* @param data The data to check on stack.
* @return true if element exists, false otherwise.
* @ingroup DataStructureMethods
*/
bool stack_has(Stack* s, int data);
/**
* @brief Prints the elements of a stack to the console.
*
* @param s The stack to print.
* @ingroup DataStructureMethods
*/
void stack_print(Stack* s);
/**
* @brief Prints the elements of a stack to the console, followed by a newline
* character.
*
* @param s The stack to print.
* @ingroup DataStructureMethods
*/
void stack_println(Stack* s);
/**
* @brief Frees the memory allocated for a stack.
*
* @param s The stack to free.
* @ingroup DataStructureMethods
*/
void stack_free(Stack* s);
// additional functions
/**
* @brief Returns the element at the top of a stack without removing it.
*
* @param s The stack to peek at.
* @return The element at the top of the stack.
* @ingroup DataStructureMethods
*/
int stack_top(Stack* s);
/**
* @brief Counts the number of odd elements in a stack.
*
* @param s The stack to search.
* @return The number of odd elements.
* @ingroup DataStructureMethods
*/
int stack_odds(Stack* s);
/**
* @brief Iterator of a stack structure.
*
* @param s The stack to search.
* @return The number of odd elements.
* @ingroup DataStructureMethods
*/
Iterator* stack_iterator(Stack *s);
#endif