-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.h
48 lines (39 loc) · 1.19 KB
/
vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*********************************FILE__HEADER*********************************\
* File: vector.h
* Author: Daniel Brodsky & Lior Katav
* Date: August-2023
* Description: API of the Vector data structure.
\******************************************************************************/
#ifndef VECTOR_H
#define VECTOR_H
/***************************** Global Definitions *****************************/
/* Initial capacity of the vector */
#define INITIAL_CAPACITY 5
/* Vector struct definition */
typedef struct {
void **items; /* Dynamic array of items */
int size; /* Current size of the vector */
int capacity; /* Current capacity of the vector */
} Vector;
/************************* Functions Declarations *************************/
/**
* Creates a new vector.
*
* @return A pointer to the newly created vector.
*/
Vector *new_vector();
/**
* Adds an element to the end of the vector.
* In case of an memory allocation error the program will exit.
*
* @param v - The vector.
* @param value - The value to be added.
*/
void push_back(Vector *v, void *value);
/**
* Frees the memory used by the vector.
*
* @param v - The vector.
*/
void free_vector(Vector *v);
#endif