-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharrayList.h
61 lines (38 loc) · 1.11 KB
/
arrayList.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
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct ArrayList_ {
void** array; //array of generic type
int lastIndex;
int size;
};
typedef struct ArrayList_ ArrayList;
ArrayList * initArrayList() {
ArrayList *arrayList = ( ArrayList* ) malloc( sizeof( ArrayList ) );
arrayList->array = (void**)malloc(3 * sizeof(void*));
arrayList->lastIndex = 0;
arrayList->size = 3;
return arrayList;
}
void *destroyArrayList( ArrayList * arrayList ) {
free(arrayList->array);
free(arrayList);
}
ArrayList *appendArrayList( ArrayList * arrayList, void * element ) {
if ( arrayList->lastIndex == arrayList->size - 1 ) {
printf("INDEX %d\n", arrayList->lastIndex);
arrayList->array = realloc( arrayList->array, 2* sizeof(arrayList->array) * sizeof(void*));
}
arrayList->array[arrayList->lastIndex] = element;
arrayList->lastIndex++;
return arrayList;
}
/**
*
*/
/*StringArray *concat( StringArray * array, char character ) {
array->string[array->lastIndex] = character;
array->lastIndex++;
return array;
} */