-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdynarray.h
More file actions
47 lines (35 loc) · 890 Bytes
/
dynarray.h
File metadata and controls
47 lines (35 loc) · 890 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef DYNARRAY
#define DYNARRAY
#define INITIAL_CAPACITY 1
#include <stdlib.h>
#define Access(type, v, i) ((type)((char*)((v).data) + ((v).cellsize * (i))))
class Vector{
public:
// Data stored at this location
void * data;
// Number of elements stored so far
int length;
// Number of cells allocated so far
int capacity;
// Size of a cell
int cellsize;
/*
Initialize
Parameters :
cellsize = How much cellsize you need.
Initializing vector based on how much cellsize is required.
*/
void Initialize(int cellsize);
/*
Extend
Parameters :
count = How many more elements you want to add.
*/
int Extend (int count = 1);
private:
/* AllocateData :
private function used to allocate more space if and when required.
*/
void AllocateData();
};
#endif