diff options
Diffstat (limited to 'vector.h')
| -rw-r--r-- | vector.h | 21 |
1 files changed, 20 insertions, 1 deletions
| @@ -8,21 +8,40 @@ typedef struct { | |||
| 8 | } vector_t; | 8 | } vector_t; |
| 9 | 9 | ||
| 10 | vector_t vector_init(int size); | 10 | vector_t vector_init(int size); |
| 11 | // initialize vector with a initial capacity of size | ||
| 11 | int size(vector_t vec); | 12 | int size(vector_t vec); |
| 13 | // returns the number of elements in vector | ||
| 12 | int capacity(vector_t vec); | 14 | int capacity(vector_t vec); |
| 15 | // returns the capacity of vector | ||
| 13 | int is_empty(vector_t vec); | 16 | int is_empty(vector_t vec); |
| 14 | int is_full(vector_t vec); | 17 | // return true if vector is empty, false if not |
| 15 | int at(vector_t vec, int index); | 18 | int at(vector_t vec, int index); |
| 19 | // returns the element at index | ||
| 16 | void push(vector_t *vec, int value); | 20 | void push(vector_t *vec, int value); |
| 21 | // add element to end of vector | ||
| 17 | void insert(vector_t *vec, int index, int val); | 22 | void insert(vector_t *vec, int index, int val); |
| 23 | // add element at index and pushing other elements to right | ||
| 18 | void delete_vec(vector_t *vec, int index); | 24 | void delete_vec(vector_t *vec, int index); |
| 25 | // delete element at index, move other elements to left | ||
| 19 | void remove_val(vector_t *vec, int value); | 26 | void remove_val(vector_t *vec, int value); |
| 27 | // remove all instance of value in vector | ||
| 20 | void prepend(vector_t *vec, int value); | 28 | void prepend(vector_t *vec, int value); |
| 29 | // add element at front of vector | ||
| 21 | int pop(vector_t *vec); | 30 | int pop(vector_t *vec); |
| 31 | // remove element at end, return value of element | ||
| 22 | void print_vec(vector_t vec); | 32 | void print_vec(vector_t vec); |
| 33 | // printf the vector in [1, 2 ] format | ||
| 23 | void destroy_vec(vector_t *vec); | 34 | void destroy_vec(vector_t *vec); |
| 35 | // deallocates the vector | ||
| 24 | int find_vec(vector_t vec, int value); | 36 | int find_vec(vector_t vec, int value); |
| 37 | // find first occurance of value in vector | ||
| 38 | // return -1 if not found | ||
| 25 | void resize_vec_check(vector_t *vec); | 39 | void resize_vec_check(vector_t *vec); |
| 40 | // checks if vector capacity needs to be doubled or halves | ||
| 41 | // if cur_size == max_size, will double | ||
| 42 | // if cur_size <= max_size/4, will half | ||
| 26 | void resize_vec(vector_t *vec, int new_capacity); | 43 | void resize_vec(vector_t *vec, int new_capacity); |
| 44 | // resizes the vector given the new_capacity | ||
| 45 | // sets max_size to new_capacity | ||
| 27 | 46 | ||
| 28 | #endif | 47 | #endif |
