blob: a40dd576db2dcc385a4bb2f4fb8f6f4e99102793 (
plain)
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
|
#include "list.h"
#include <stdlib.h>
LIST* list_add(LIST* list, void* item)
{
if (list == NULL)
{
list = (LIST*)malloc(sizeof(LIST));
list->size = 0;
list->list = (void**)malloc(sizeof(0));
}
list->size ++;
void** new_list = (void**)reallocarray(list->list, list->size, sizeof(void*));
new_list[list->size-1] = item;
list->list = new_list;
return list;
}
LIST* list_remove(LIST* list, unsigned int pos)
{
for(unsigned int i = pos; i < list->size - 1; i++)
list->list[i] = list->list[i + 1];
list->size--;
void** new_list = reallocarray(list->list, list->size, sizeof(void*));
list->list = new_list;
return list;
}
void list_free(LIST* list) {
for (unsigned int x = 0; x < list->size; x++)
free(list->list[x]);
free(list->list);
free(list);
}
|