-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_array.h
More file actions
65 lines (47 loc) · 1.56 KB
/
dynamic_array.h
File metadata and controls
65 lines (47 loc) · 1.56 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// written by Sam Goodrick
// contact at sdg31@zips.uakron.edu
#ifndef DYNAMIC_ARRAY_H
#define DYNAMIC_ARRAY_H
// THIS STRUCTURE ABSTRACTS DYNAMICALLY ALLOCATED MEMORY
// <<DO NOT>> ACCESS MEMBERS DIRECTLY
typedef struct
{
double* array;
// points to the first element
double* first;
// points to the position after the last element
double* last;
// pointer to the last place in array memory
double* limit;
// current size of array memory
int capacity;
// amount of elements actually in the array
int size;
}dynamic_array;
// construct a dynamic array of capacity 4
// memory is uninitialized
void construct( dynamic_array* );
// free all memory and set member pointers to NULL
void destruct( dynamic_array* );
// double the size of the dynamic array
// original array occupies the first half of the new array
// and new memory is uninitialized
void resize( dynamic_array* );
// reserve n elements in the array, all uninitialized
void reserve( dynamic_array*, int );
// insert an element into the back of the array
// returns a pointer to the inserted element
double* push_back( dynamic_array*, double );
// remove the last element in the array
// returns the value of the removed element
double pop_back( dynamic_array* );
// insert element at position n
// return a pointer to the inserted element
double* insert( dynamic_array*, int, double );
// returns the value at array[n]
double index( dynamic_array*, int );
// returns a pointer to the first element
double* front( dynamic_array* );
// returns a pointer to the last element
double* back( dynamic_array* );
#endif