27 lines
625 B
C
27 lines
625 B
C
|
#pragma once
|
||
|
|
||
|
#include <stddef.h>
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
struct Stack {
|
||
|
size_t size;
|
||
|
size_t capacity;
|
||
|
void* data;
|
||
|
};
|
||
|
|
||
|
void stack_init(struct Stack* stack, size_t size);
|
||
|
void stack_push(struct Stack* stack, void* data, size_t len);
|
||
|
void* stack_pop(struct Stack* stack, size_t len);
|
||
|
void stack_free(struct Stack* stack);
|
||
|
|
||
|
inline void stack_push_int(struct Stack* stack, int value) {
|
||
|
stack_push(stack, &value, sizeof(int));
|
||
|
}
|
||
|
|
||
|
inline bool stack_pop_int(struct Stack* stack, int* value) {
|
||
|
void* d = stack_pop(stack, sizeof(int));
|
||
|
if (d == NULL) return false;
|
||
|
*value = *(int*)(d);
|
||
|
return true;
|
||
|
}
|