1#include "list.h"
2#include <stdlib.h>
3
4LIST* list_add(LIST* list, void* item)
5{
6
7 if (list == NULL)
8 {
9 list = (LIST*)malloc(sizeof(LIST));
10 list->size = 0;
11 list->list = (void**)malloc(sizeof(0));
12
13 }
14
15 list->size ++;
16 void** new_list = (void**)reallocarray(list->list, list->size, sizeof(void*));
17
18 new_list[list->size-1] = item;
19 list->list = new_list;
20
21 return list;
22
23}
24
25LIST* list_remove(LIST* list, unsigned int pos)
26{
27 for(unsigned int i = pos; i < list->size - 1; i++)
28 list->list[i] = list->list[i + 1];
29
30 list->size--;
31
32 void** new_list = reallocarray(list->list, list->size, sizeof(void*));
33 list->list = new_list;
34
35 return list;
36}
37
38void list_free(LIST* list) {
39 for (unsigned int x = 0; x < list->size; x++)
40 free(list->list[x]);
41
42 free(list->list);
43 free(list);
44}
45
46
47void *list_get(LIST *list, unsigned int index) {
48 if (list == NULL)
49 return NULL;
50
51 if (index < list->size)
52 return list->list[index];
53
54 return NULL;
55}