lib: add basic stack type
I can't believe I've made it this far without needing one
This commit is contained in:
parent
a10509f1e5
commit
a6b7d9b42d
3 changed files with 85 additions and 0 deletions
24
include/lib/stack.h
Normal file
24
include/lib/stack.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _STACK_H_
|
||||
#define _STACK_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct stack_node {
|
||||
struct stack_node *next;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct stack {
|
||||
struct stack_node *top;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
void stack_init();
|
||||
struct stack *stack_create();
|
||||
void stack_destroy(struct stack *stack);
|
||||
void stack_push(struct stack *stack, void *data);
|
||||
void *stack_pop(struct stack *stack);
|
||||
void *stack_peek(struct stack *stack);
|
||||
|
||||
#endif /* _STACK_H_ */
|
||||
Loading…
Reference in a new issue