Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdint.h>
- #include <stdio.h>
- typedef struct vct {
- float* data;
- size_t base;
- size_t capacity;
- size_t size;
- } vct;
- vct* vct_create(size_t capacity)
- {
- vct* vector = malloc(sizeof(vct));
- vector->data = malloc(sizeof(float)*capacity);
- vector->base = 0;
- vector->capacity = capacity;
- vector->size = 0;
- }
- vct vct_destroy(vct* vector)
- {
- free(vector->data - vector->base);
- free(vector);
- }
- void vct_push_back(vct* vector, float value)
- {
- vector->data[vector->base + (vector->size++)] = value;
- }
- float vct_pop_back(vct* vector)
- {
- return vector->data[vector->base + (--vector->size)];
- }
- float vct_pop_front(vct* vector)
- {
- return vector->data[(vector->base++)];
- }
- int main()
- {
- vct* vector = vct_create(100);
- for(int i=0; i<10; ++i) {
- vct_push_back(vector, i+10.2);
- }
- for(int i=vector->base; i<vector->size; i++) {
- printf("%f\n", vector->data[i]);
- }
- printf("popping: %f\n", vct_pop_back(vector));
- printf("popping: %f\n", vct_pop_back(vector));
- for(int i=vector->base; i<vector->size; i++) {
- printf("%f\n", vector->data[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement