This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
sys_prog/collections/stack.c

21 lines
595 B
C
Raw Normal View History

2019-08-23 18:22:55 +00:00
// vim: set et sw=4 ts=4 tw=80:
#include "./collections.h"
static inline void vector_expand(vector_t* self) {
if (self->size >= self->capacity) {
self->capacity *= 2;
self->elements = realloc(self->elements,
sizeof(void*) * self->capacity);
}
}
void vector_init(vector_t* self, const size_t initial_capacity) {
self->elements = (void**) malloc(sizeof(void*) * initial_capacity);
self->size = 0;
self->capacity = initial_capacity;
}
void vector_insert(vector_t* self, const size_t position, const void* element) {
vector_expand(self);
}