-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
68 lines (55 loc) · 1.69 KB
/
stack.h
File metadata and controls
68 lines (55 loc) · 1.69 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
#ifndef STACK_H
#define STACK_H
#include <stdlib.h>
#include <stdbool.h>
/* Structs */
/* Fixed size generic stack. */
struct stack_t {
size_t size;
size_t capacity;
void **items;
};
/* Methods */
/*
Method to initialize stack.
@param stack struct stack_t *: pointer to the stack to init.
@param size size_t: the max size of the stack.
*/
void stack_init(struct stack_t *stack, size_t capacity);
/*
Destructor method for a stack.
@param stack struct stack_t *: pointer to the stack to be destroyed.
*/
void free_stack(struct stack_t *stack);
/*
Predicate method to check if the stack is empty.
@param stack struct stack_t *: pointer to the stack to check.
@returns the empty state of the stack.
*/
bool stack_empty(struct stack_t *stack);
/*
Predicate method to check if the stack is full.
@param stack struct stack_t *: pointer to the stack to check.
@returns the full state of the stack.
*/
bool stack_full(struct stack_t *stack);
/*
Method to insert an item into a stack.
@param stack struct stack_t *: the stack to push to.
@param item void*: the item to push.
@returns bool if the item was successfully added.
*/
bool stack_push(struct stack_t *stack, void *item);
/*
Method to get the first item in the stack and remove it.
@param stack struct stack_t *: the stack to get the item from.
@returns a void pointer to the item or NULL stack is empty.
*/
void *stack_pop(struct stack_t *stack);
/*
Method to get the first item in the stack.
@param stack struct stack_t *: the stack to get the item from.
@returns a void pointer to the item or NULL stack is empty.
*/
void *stack_get(struct stack_t *stack);
#endif