DSA Hacking Club Library
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1
13
14#ifndef STACK_H
15#define STACK_H
16
17#include <stdbool.h>
18
19// --- Public Constants and Definitions ---
20
29#define STACK_EMPTY (-2147483647 - 1)
30
37typedef struct {
38 int *data;
39 int top;
41} Stack;
42
43// --- Public Function Prototypes ---
44
54Stack *stack_create(int capacity);
55
63void stack_destroy(Stack *s);
64
73bool stack_push(Stack *s, int value);
74
81int stack_pop(Stack *s);
82
89int stack_peek(const Stack *s);
90
97int stack_size(const Stack *s);
98
105bool stack_is_empty(const Stack *s);
106
107#endif // STACK_H
void stack_destroy(Stack *s)
Destroy a stack and release its allocated memory.
Definition stack.c:20
int stack_size(const Stack *s)
Get the current number of elements in the stack.
Definition stack.c:47
int stack_pop(Stack *s)
Pop the value at the top of the stack.
Definition stack.c:35
int stack_peek(const Stack *s)
Return the value at the top of the stack without removing it.
Definition stack.c:41
bool stack_push(Stack *s, int value)
Push a value onto the top of the stack.
Definition stack.c:27
Stack * stack_create(int capacity)
Allocate and initialize a new stack.
Definition stack.c:4
bool stack_is_empty(const Stack *s)
Check whether the stack is empty.
Definition stack.c:49
Representation of a stack of integers.
Definition stack.h:37
int * data
Pointer to the dynamically allocated array of integers.
Definition stack.h:38
int capacity
Maximum number of elements the stack can hold.
Definition stack.h:40
int top
Index of the current top element (-1 if empty)
Definition stack.h:39