-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_array.h
More file actions
29 lines (21 loc) · 781 Bytes
/
dynamic_array.h
File metadata and controls
29 lines (21 loc) · 781 Bytes
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
#include <unistd.h>
#ifndef DYNAMIC_ARRAY_H
#define DYNAMIC_ARRAY_H
typedef struct {
char **data;
size_t size; // Number of elements in the Array
size_t capacity; // Current Capacity of the Array
} DynamicArray;
// Create a new DynamicArray with given initial capacity
DynamicArray* da_create(size_t init_capacity);
// Add element to Dynamic Array at the end. Handles resizing if necessary
void da_put(DynamicArray *da, const char* val);
// Get element at an index (NULL if not found)
char *da_get(DynamicArray *da, const size_t ind);
// Delete Element at an index (handles packing)
void da_delete(DynamicArray *da, const size_t ind);
// Print Elements line after line
void da_print(DynamicArray *da);
// Free whole DynamicArray
void da_free(DynamicArray *da);
#endif